Mike Torrettinni
Members-
Content Count
1509 -
Joined
-
Last visited
-
Days Won
3
Everything posted by Mike Torrettinni
-
Micro optimization: Split strings
Mike Torrettinni replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Thanks, good eyes! Well, yes, it might seems the opposite, but I do try to make it right 😉 I need more practice, -
Delphi is 26 years old - Marco's blog
Mike Torrettinni posted a topic in Tips / Blogs / Tutorials / Videos
Delphi is 26 years old! And this: "...over 26 years has been used to build applications used by billions of people..." is pretty impressive achievement! 😉 https://blogs.embarcadero.com/26-years-of-delphi/ -
Delphi is 26 years old - Marco's blog
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
And next step is of course AI, I guess : -
Delphi is 26 years old - Marco's blog
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Oh, the fun times of drawing stars for school assignment in Turbo Pascal 😉 -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Thanks, I agree! Sometimes is also fun 😉 -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
I actually have similar situations quite often, and in topic using Pos before StringReplace I describe the benefit because of how many developers are affected. So, as you describe, not all optimization affect all users. But if it does some, why shouldn't I improve it? I have a feature that exports/import data and every feature in project ads some execution time, and every year I optimize parts of it so that it stays around 20s. If I didn't optimize it would probably be 60s by now. The thing is that every time I profile it, I see something I can improve, that I didn't see the last time - because I have more experience now. So, is not just a problem of deciding what to optimize, is also what I know how to optimize. -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
I searched for it but can't find it. Can you point me to a comment, topic? -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Thanks. Oh, don't get me wrong, I had my share of mistakenly going down the road of wrong path, and I sure will do again 😉 Unfortunately in most of my cases I can't just replace parts of the code with already made example of faster. Either it doesn't exist, or I don't know about it or it would take a big sum of money to hire an expert. Not sure if you noticed some of my topics about optimization, micro-optimization... as comments show some are really triggered that I post such basic things as big 'revelations', for me is a day by day discovery of new things. A lot of them because I try to optimize wrong things, some of them proved to be real improvements. -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Thank you, I read the same link a while ago and the best answer has very clearly written: " What this means is that, in the absence of measured performance issues you shouldn't optimize because you think you will get a performance gain. There are obvious optimizations (like not doing string concatenation inside a tight loop) but anything that isn't a trivially clear optimization should be avoided until it can be measured. " I understand this as: as long as it's a measured bottleneck, it is worth looking into. If you want to get away from the theory, I would love to hear about your last bottleneck, how you defined it. -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
I do understand that not all applications need to be really fast and optimized. My project is kind of a parser project, so will never be fast enough - or, best outcome would be for the parsing process to be done within a timeframe of user pressing mouse button down and releasing it. So, I'm trying to be better at assessing bottlenecks. If 10% reduced process runtime is not worth improving, what is your criteria? How did you decide your last bottleneck needs fixing? -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Isn't that how you learn, get experience? You tackle a problem and try to fix, improve it. Sometimes it works, sometimes the experience is not there, yet, and try another approach or come back at another time. -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
I've been reading a lot about optimization and it's interesting to see that phrase 'premature optimization' is usually just a BS, except for extremely basic cases. I agree with this and by attempting some minor optimizations I learned how to optimize other bigger parts of the code. -
Is Delphi still taught in schools?
Mike Torrettinni posted a topic in Tips / Blogs / Tutorials / Videos
I noticed @DesadaptadoDimensional said he is learning Delphi, I guess in school. Do we still have schools that teach Delphi, what countries? I remember schools in Turkey are supposed to start offering Delphi classes, but I don't know the status of this: -
How do you identify bottleneck in Delphi code?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Yes, I use profiler to see what methods gets called most and what methods take what percentage of total runtime. Then I decide which ones to optimize sometimes based on percentage of total runtime, sometimes based on number of calls. You don't measure the runtime of methods? Sometimes is very obvious what is bottleneck, sometimes is not... if you have 5 methods takes 15% of total runtime each, how do you decide which one to work on? Some methods could use some simple optimization tricks, some need different data structure to work with, different sorting algorithms... it can take hours to implement new approach, but then you measure it and you didn't gain anything. -
Micro optimization: String starts with substring
Mike Torrettinni posted a topic in Algorithms, Data Structures and Class Design
I use Copy and MidStr a lot, and I wanted to test which one is best to be used to check if String starts with substring, so I can refactor code and use just one function. There are also String.StartsWith helper and StartsStr function. So, I ran some simple tests and seems to be that Copy is fastest option: I noticed this question on SO: Difference between System.copy and StrUtils.MidStr https://stackoverflow.com/q/13411139 which explains that MidStrs uses Copy (I checked and in Delphi 10.2.3 it does), so Copy should be faster then. Substring exists at the start: Short string: Copy: 166 // WINNER MidStr: 184 StartsWith: 511 StartsStr: 792 Long string: Copy: 179 // WINNER MidStr: 190 StartsWith: 524 StartsStr: 840 Substring NOT exists at the start: Short string: Copy: 169 // WINNER MidStr: 180 StartsWith: 514 StartsStr: 886 Long string: Copy: 170 // WINNER MidStr: 182 StartsWith: 517 StartsStr: 897 Does anybody know of any faster option to check if string starts with substring? program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Diagnostics, System.StrUtils; const cMaxLoop = 10000000; cText = 'Error: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'; cTextNoHits = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'; cStartsWithShort = 'E'; cStartsWithLong = 'Error:'; var vSW: TStopWatch; i, vLen: integer; vResult: boolean; begin Writeln('Substring exists at the start:'); // Short string Writeln('Short string:'); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := Copy(cText, 1, 1) = cStartsWithShort; Writeln(' Copy: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := MidStr(cText, 1, 1) = cStartsWithShort; Writeln(' MidStr: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := cText.StartsWith(cStartsWithShort); Writeln(' StartsWith: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := StartsStr(cStartsWithShort, cText); Writeln(' StartsStr: ' + vSW.ElapsedMilliseconds.ToString); // Long string Writeln('Long string:'); vLen := Length(cStartsWithLong); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := Copy(cText, 1, vLen) = cStartsWithLong; Writeln(' Copy: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := MidStr(cText, 1, vLen) = cStartsWithLong; Writeln(' MidStr: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := cText.StartsWith(cStartsWithLong); Writeln(' StartsWith: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := StartsStr(cStartsWithLong, cText); Writeln(' StartsStr: ' + vSW.ElapsedMilliseconds.ToString); Writeln; // Text DEOS NOT start with selected string Writeln('Substring NOT exists at the start:'); // Short string Writeln('Short string:'); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := Copy(cTextNoHits, 1, 1) = cStartsWithShort; Writeln(' Copy: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := MidStr(cTextNoHits, 1, 1) = cStartsWithShort; Writeln(' MidStr: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := cTextNoHits.StartsWith(cStartsWithShort); Writeln(' StartsWith: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := StartsStr(cStartsWithShort, cTextNoHits); Writeln(' StartsStr: ' + vSW.ElapsedMilliseconds.ToString); // Long string Writeln('Long string:'); vLen := Length(cStartsWithLong); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := Copy(cTextNoHits, 1, vLen) = cStartsWithLong; Writeln(' Copy: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := MidStr(cTextNoHits, 1, vLen) = cStartsWithLong; Writeln(' MidStr: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := cTextNoHits.StartsWith(cStartsWithLong); Writeln(' StartsWith: ' + vSW.ElapsedMilliseconds.ToString); vSW := TStopWatch.StartNew; for i := 1 to cMaxLoop do vResult := StartsStr(cStartsWithLong, cTextNoHits); Writeln(' StartsStr: ' + vSW.ElapsedMilliseconds.ToString); readln; end. -
Micro optimization: String starts with substring
Mike Torrettinni replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
@Fr0sT.Brutal Your StrIsStartingFrom wins for longer string, and if I put Exit(false) and remove initial Result := false it improves performance for additional 2%. Thanks! When checking for shorter string, like 1 char (but we don't know so we can't compare by char), StrStartsWith wins for about 20%. -
Is Delphi still taught in schools?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Yes, I guess you are correct. Delphi CE doesn't seem to targeted to students, anyway. -
Is Delphi still taught in schools?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
I guess the question would be more appropriate about Pascal and it's versions. But it seems is not completely out of the schools, around the world, just very rare. -
It seems I missed the point of the question... where can I read more about this?
-
I do this often, but manually: I create new unit, move main method and all dependencies (sometimes compile is needed to discover all dependencies). I also take advantage of this to improve naming, code refactor, also usually add enums and new types. Then I use compile or Find in files and replace to make sure all old calls are updated with new unit in uses clause. I do this with a very messy code and it ends with nicely organized unit.
-
Is Delphi still taught in schools?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Obviously there must be more than it seems, because Lazarus is being used in schools, too: https://stackoverflow.com/questions/66188063/how-to-build-an-application-to-calculate-weight-and-mole-percent-from-a-chemica -
Is Delphi still taught in schools?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
In school I learned Pascal and C. I guess Pascal was easier since I picked it Delphi later on. -
Is Delphi still taught in schools?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
Oh, yes Pascal, of course. Didn't know FPC is used anywhere except by small group of enthusiasts. Good! -
Is Delphi still taught in schools?
Mike Torrettinni replied to Mike Torrettinni's topic in Tips / Blogs / Tutorials / Videos
What do you mean? He is learning it in school... so are you talking about your country? As far as I know its not taught in US schools. -
Delphi Native Code: Fast or Reliable?
Mike Torrettinni posted a topic in Tips / Blogs / Tutorials / Videos
A question for Delphi developers who also use .Net: I'm reading this OLD (2008) Marco's blog and the comments: https://blog.marcocantu.com/blog/delphi_native_code.html and wondering if it's still the same today: that .Net world changes so fast they need to keep updating to latest framework versions of old stuff is not working anymore, opposite of Delphi? My oldest project is running for 15+years, and except for code updates to use the latest Delphi feature, I don't remember any Windows changes that I needed to take into consideration or project would not work anymore. Was I just lucky and there was a breaking change in Windows where Delphi projects had to be updated or Marco is still right about Delphi today - it just works, while others don't?