Open amlan-sw opened 1 year ago
Here's a too simple loop — https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/toosimple.html
Notice that swapping the order of two statements can have a dramatic impact.
Notice that using global vars vs local vars can have a dramatic impact.
Notice that the particular language implementation can have a dramatic impact.
note: we need simple operation on loop like a+=4 so the optimizer of language 'dont cheat' the output, because empty operation might make some language optimizer skip loop operation
You should use a more complex operation in the loop that can't be optimized out. A good, optimizing compiler/interpreter will have little issue with optimizing out a loop that just performs increments using a constant value. As demonstrated by your timings, GCC had no issue optimizing out the loop when optimization was enabled and completed the program in just 0.003s which would be impossible on all current microprocessors if it had actually ran that loop 1,000,000,001 times.
sometime we don't need complicated algorithm to see performance of programming language, we just need to see how these language loop's implemetation, all benchmark game like binarytree, fasta, etc just only test loop implementation of language and sometime benchmark implementation syscall like 'print' to console through loop
example just loop for 1000_000_000 (billion) in linux bash for various language, i'm using digitalocean cloud with centos7
-
-
-
note: we need simple operation on loop like a+=4 so the optimizer of language 'dont cheat' the output, because empty operation might make some language optimizer skip loop operation