For 100 operations it might seem fast but for 10000 operations it starts to show a good difference.
here is the runtime of three functions with 10000 operations
6.550000000160594
2.3500000001508425
2.0000000000575113
Unfortunately four numbers doesn't explain much.
Modulo is usually one machine code instruction. Other parts of the program will probably dwarf its execution time, such as I/O.
Agreed, the problem isn't that it is slower (unless you're building a military grade FizzBuzz the difference is imperceptible). The actual problem (or I should say, the problem much more likely to be encountered) is when a change request comes in to add rules to "Woof on multiples of 7" the number of cases to check doubles (from 15, 5, 3 to 105, 35, 21, 15, 7, 5, 3)
Yes true...
And when working in real-life applications...
we often encounter these sort of problems, where the correct algorithm wins.
just like Page rank over others...
There's your problem. It is quite fast in itself.
For 100 operations it might seem fast but for 10000 operations it starts to show a good difference.
here is the runtime of three functions with 10000 operations
6.550000000160594
2.3500000001508425
2.0000000000575113
Unfortunately four numbers doesn't explain much.
Modulo is usually one machine code instruction. Other parts of the program will probably dwarf its execution time, such as I/O.
Agreed, the problem isn't that it is slower (unless you're building a military grade FizzBuzz the difference is imperceptible). The actual problem (or I should say, the problem much more likely to be encountered) is when a change request comes in to add rules to "Woof on multiples of 7" the number of cases to check doubles (from
15, 5, 3
to105, 35, 21, 15, 7, 5, 3
)Yes true...
And when working in real-life applications...
we often encounter these sort of problems, where the correct algorithm wins.
just like Page rank over others...
Solve today's problem. Fizzbuzz is Fizzbuzz.