Switch vs Object

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
switch
(function(test){
    var bar;

    switch(bar) {
        case 1:
            bar = 'red';
            break;
        case 2:
            bar = 'blue';
            break;
        case 3:
            bar = 'yellow';
            break;
        case 4:
            bar = 'green';
            break;
        case 5:
            bar = 'black';
            break;
    }

    return bar;
})(5);
ready
object
(function(test){
    return { 1: 'red', 2: 'blue', 3: 'yellow', 4: 'green', 5: 'black' }[ test ];
})(5);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.