Speed comparison of MID$ vs ASC - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13) +--- Thread: Speed comparison of MID$ vs ASC (/showthread.php?tid=2116) Pages:
1
2
|
Speed comparison of MID$ vs ASC - SMcNeill - 10-22-2023 As it seems everyone is always trying to make their stuff run as fast as possible, I want to take a moment to once again point out the difference in speed between using STRING manipulation (such as MID$) verses the equivalent numeric manipulation (such as with ASC). Take a brief moment to look at the following code, and compare the run times of these two simple routines: Code: (Select All)
Replacing 100 million characters inside a string with another character, so give this a wee bit to run. (Particularly if you're on an older, slower PC.) On my machine, this takes about 8 seconds from start to finish, so you can use that as some sort of general starting benchmark of what to expect with a higher-end PC. (If your machine is 10 years old, or a bargain basement model, give it 30+ seconds to run. If you're on something older than that, go grab yourself a cup of coffee and kindly report the results when your antique finishes two hours from now -- I'd love to see the comparison values on some older hardware!) Most folks seem to forget that in QB64PE, you can add a second exponent to the ASC command to get the particular character you want. Even more folks seem to have absolutely no knowledge in the fact that ASC is also a SUB and not just a FUNCTION, and that the SUB version can be used to assign values to your string! If you guys are ever the type to be concerned about the speed and performance of your programs, **REMEMBER** these two commands and the features they possess. They're quite a bit faster than MID$, and can improve program performance considerably! RE: Speed comparison of MID$ vs ASC - SMcNeill - 10-22-2023 @TerryRitchie I don't know if you have a tutorial lesson on these two commands, or not. If not, you might want to consider adding one (or highlighting the speed difference in your existing one, if it exists), so folks will get more familiar with using ASC and its extended syntax like this. It really is a LOT faster than using MID$, when you don't have to! RE: Speed comparison of MID$ vs ASC - Dimster - 10-22-2023 Your computer is faster than mine. RE: Speed comparison of MID$ vs ASC - SMcNeill - 10-22-2023 (10-22-2023, 02:05 PM)Dimster Wrote: Your computer is faster than mine. Still about the difference I'd expect on the ratio for performance between MID$ and ASC. A 1000% speed boost isn't anything to sneeze over! RE: Speed comparison of MID$ vs ASC - TerryRitchie - 10-22-2023 (10-22-2023, 03:21 AM)SMcNeill Wrote: @TerryRitchie I don't know if you have a tutorial lesson on these two commands, or not. If not, you might want to consider adding one (or highlighting the speed difference in your existing one, if it exists), so folks will get more familiar with using ASC and its extended syntax like this. It really is a LOT faster than using MID$, when you don't have to!I have both ASC and MID$ in Lesson 9 but I just checked and I don't have the extended syntax for ASC detailed. I'll make sure to add that shortly. I've been scarce the past few days because I'm once again redoing the entire tutorial site. I had all the code listings embedded in the pages but because I can't trust that method now I'm converting the code listings over to pure HTML. I'm currently up to chapter 10. I found a way to use the Export to HTML feature in the IDE and still retain the format while incorporating the listing in HTML. It takes longer than embedding but it will guarantee the listings are also available. I have a feeling SquareSpace is not going to be much help unless I pay their monthly fee. When I asked them about embedding not working all I got was a canned response and of course information on how to become a "full" SquareSpace member. Thank you Google for once again abandoning another one of your projects. RE: Speed comparison of MID$ vs ASC - SpriggsySpriggs - 10-23-2023 I had no idea you could even do replacements with ASC but maybe I will from now on. Seems fairly handy. RE: Speed comparison of MID$ vs ASC - TerryRitchie - 10-26-2023 (10-22-2023, 03:21 AM)SMcNeill Wrote: @TerryRitchie I don't know if you have a tutorial lesson on these two commands, or not. If not, you might want to consider adding one (or highlighting the speed difference in your existing one, if it exists), so folks will get more familiar with using ASC and its extended syntax like this. It really is a LOT faster than using MID$, when you don't have to! I updated Lesson 9 in the tutorial with changes. Thanks for the head's up Steve. A lot of the tutorial I wrote back in 2013. Many new features have come along since (especially with pe) so I need to go through the tutorial and see what else may be missing. RE: Speed comparison of MID$ vs ASC - bobalooie - 10-27-2023 4.066 sec vs 0.483 sec Vector GP66 gaming laptop. Not shabby, good tip. RE: Speed comparison of MID$ vs ASC - TarotRedhand - 10-31-2023 All well and good for replacing single characters but not so useful I suspect for replacing more than one character at a time e.g. Replace 'Art' with 'Tar' or 'Rat'. FWIW, ~13 seconds for MID$ and ~1 second for ASC. TR RE: Speed comparison of MID$ vs ASC - OldMoses - 11-03-2023 I've generally defaulted to the use of MID$. I was aware that ASC existed, but didn't make much use of the knowledge. Good stuff to remember. My machine: 6.979 MID$ 0.605 ASC |