I think, is the same, but the first one is more readable
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Look at the ASM output and figure out if there are different calls used and count the CPU cycles together if you need
In practice both do the same thing maybe even equally fast, but in theory depending on the compiler and how it parses the source code, there can be a slight 0.1% speed difference that doesn't really count in overall performance...
the performance is not the only thing in question.
normally, you would use a random number not only for output, but also for calculations.
the first version already holds the value in a variable, the second one only provides the string.
well, after checking it out some more and considering the input from you folks i've decided to go with the second one and kind of combine all your words of wisdom into one solution. I only really need the string, it helps 'neaten' the procedure it lives in by reducing clutter in the procedure and makes the overall procedure more readable, and the time differences are not that great between the two enough to really matter. Thanks for your input folks
If this is such a tight loop that a difference like this is being sought for perf reasons, you many want to consider a faster random() proc. Not criticising PB's but it's chosen as a good balance of speed and randomness. Just like you wouldn't use it in a security application perhaps you should replace it for a hi-perf one. It's a black box after all.
Depends on what you need
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
I believe a couple are implemented in the tips section already.
Sounds like, from the question, that you are after one optimised for speed.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein