calculations after boxing numbers inside an object

JavaScript performance comparison

Test case created by Victor Maia

Info

If one had to box every number object inside another object for some reason (eg keeping track of parental relationships), what would be the performance costs?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function number(n){
        return {type:'number',parent:undefined,value:n};
    }
    function sum(a,b){
        return {type:'number',parent:undefined,value:a.value+b.value};
    }
    boxed_num = number(0);
    normal_num = 0;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
normal number sum
normal_num = normal_num + 1;
pending…
boxed number sum
boxed_num = boxed_num + number(1);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment