3
kira
6y

;)

function getReason(num) {
switch (num) {
case 1:
console.log("Love to create something new!");
break;

case 2:
console.log("It's fucking cool!");
break;

case 3:
console.log("Money!");
break;

default:
console.log("Fuck offffff");
break;
}
}

Comments
  • 1
    An array would be 2% faster lol
  • 9
    var reason = getReason(1);
    console.log(reason); // > undefined

    If you prefix your function name with 'get', make sure it returns something.
  • 0
    @nitwhiz I am expressing reasons with rank wise and I don't want to disclose all the reasons at once ;)
  • 0
    @hack Very touchy :)
    .
    .
    *edit :
    printReason(reason)
  • 1
    @nitwhiz it depends on the language, the system it is running on and how often it is called.
  • 0
    @Codex404 really? I actually made a jsperf for it, that's where I took the 2 percent from.:D

    But I guess array access (mov) is always faster than jmp, sub, mov, ret.^^
  • 1
    @nitwhiz array access is quicker indeed, but if the array has to be initialized every single time that also cost time.
  • 0
    @Codex404 of course, yeah. But I guess it's common sense to put the array outside of this function.^^
  • 0
    @nitwhiz and polluting the outer scope for a single function?

    How is the RAM usage?
  • 0
    @Codex404 but you'd use that memory once, you don't need to allocate and garbage collect it again and again and again.

    Fragmented memory and slow performance vs upfront memory cost and high performance.
Add Comment