I think the problem with your code might be that your second "switchCase" is running with a lamba inside of a lamba, so the actual code you want to test does not get hit.
Correct me if I'm wrong.
Here are my results...
It includes the test of the buggy one.
Note:
I ran each "timeInLoop" separately, and about 5 times each, and reported the lowest score.
import{or,switchCase}from"rubico";importtimeInLoopfrom"./timeInLoop";constisOdd=x=>x%2===1;//@perftests//isOdd: 1e+6: 10.013mstimeInLoop("isOdd",1e6,()=>isOdd(4));// isOdd_ternary: 1e+6: 9.726mstimeInLoop("isOdd_ternary",1e6,()=>{isOdd(4)?1:0});// isOdd_ifElse: 1e+6: 9.846mstimeInLoop("isOdd_ifElse",1e6,()=>{if(isOdd(4))return'odd'elsereturn'even'});// isOdd_switch: 1e+6: 9.776mstimeInLoop("isOdd_switch",1e6,()=>{switch(isOdd(4)){casetrue:return'odd'default:return'even'}});//isOdd_rubicoSwitchCase: 1e+6: 152.762mstimeInLoop("isOdd_rubicoSwitchCase",1e6,()=>{switchCase([()=>isOdd(4),()=>'odd',()=>'even'])});//@BUG: a nested lambda, the code to be perftested never executes// isOdd_rubicoSwitchCaseExtraLambda: 1e+6: 10.667mstimeInLoop("isOdd_rubicoSwitchCaseExtraLambda",1e6,()=>{()=>switchCase([isOdd,()=>'odd',()=>'even'])});
I looked into it a bit, turns out the differences we were seeing were due to mocha. I was using it to organize the benchmarks, but I see now that I should probably get closer to the ground. I'll also revise rubico's timeInLoop to model yours more closely.
I think the problem with your code might be that your second "switchCase" is running with a lamba inside of a lamba, so the actual code you want to test does not get hit.
Correct me if I'm wrong.
Here are my results...
It includes the test of the buggy one.
Note:
I ran each "timeInLoop" separately, and about 5 times each, and reported the lowest score.
I looked into it a bit, turns out the differences we were seeing were due to mocha. I was using it to organize the benchmarks, but I see now that I should probably get closer to the ground. I'll also revise rubico's timeInLoop to model yours more closely.
Great.
Keep up the good work, and let me know how it progresses and if you come up with more ideas.