if-else VS case-else VS case

2022-08-15 Thread drkameleon
> Are you writing an interpreter? Yep. haha. (And I believe we have talked about similar things in the past... ;-) ) Basically, given that the language is already quite mature and used in different projects, I decided it was high time to start benchmarki

if-else VS case-else VS case

2022-08-14 Thread mratsim
Are you writing an interpreter? Your benchmark might be a bit too simple and compilers might optimize some stuff away. Here are mine like 4 years ago, at the bottom: import random, sequtils, times

if-else VS case-else VS case

2022-08-04 Thread treeform
As writer of benchy I trust that benchmark the most. My gut feeling is that there is no real difference and benchy shows that. You are benching your CPU's microcode jump prediction. The compiler can generate different code for different cases which might results in different performance. I feel

if-else VS case-else VS case

2022-08-04 Thread r3c
One might see a difference when using C compiler that generates jump tables, it should be several times faster than if-else

if-else VS case-else VS case

2022-08-04 Thread drkameleon
Hmm... Interesting. Then I guess I'm miscalculating the timings?

if-else VS case-else VS case

2022-08-04 Thread DMisener
Using **bency** benchmarking tool -- I get: nim git:(master) ✗ nim r -d:release test_case.nim name ... min time avg timestd dv runs if-else ... 20.048 ms 20.724 ms±0.370 x241 case-else ...

if-else VS case-else VS case

2022-08-04 Thread drkameleon
My results are similar, with `-d:danger` included (which I hadn't tried before). Basically, the case-else version seems like the best of the bunch. Now, here comes an even weirder realization... If I add this to the mix a `.computedGoTo.` benchmark, the results baffle me even more:

if-else VS case-else VS case

2022-08-04 Thread Prestige
I'm not sure, but I'll provide my runtimes of these benchmarks: `nim r -d:release foo.nim`: if-else: 0.086073489 case-else: 0.10265143 case-all: 0.14253516 Run `nim r foo.nim`: if-else: 0.346636164 case-else: 0.249107282 case-all: 0.313689

if-else VS case-else VS case

2022-08-04 Thread drkameleon
I've been experimenting a bit with the performance of the following constructs... and I'm a bit baffled by the results (especially the last 2). And they are totally consistent, regardless of how many times I run my benchmarks. Can somebody explain to me what is going on? type