calculations after boxing numbers inside an object

JavaScript performance comparison

Test case created by Victor Maia


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

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;

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;
boxed number sum
boxed_num = boxed_num + number(1);

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment