py2js

Benchmark created on


Setup

let obj = {
	a: 32,
	b: 52
};
let obj2 = {
	a:32,
	b: 52
};

let arr = [obj, obj2];

function jsobj2pyobj(jsobj, _this = null) {
	switch(jsobj) {
      case true:
      case false:
        return jsobj
    }

    if(jsobj === undefined){
        return null
    }else if(jsobj === null){
        return null
    }

    if(Array.isArray(jsobj)){
        return jsobj.map(jsobj2pyobj)
    }else if(typeof jsobj === 'number'){
       return null
    }else if(typeof jsobj == "string"){
        return null
    }else if(typeof jsobj == "function"){
            return null
    }

    if(jsobj.kw) {
        return jsobj
    }
	
	return jsobj
}


let wrapper = jsobj2pyobj(obj);
let array_wrapper = jsobj2pyobj(arr);

let wm = new WeakMap();
wm.set(obj, wrapper);
wm.set(arr, array_wrapper);

function cache(obj) {
	obj = wm.get(obj);
	if(obj !== null)
    	return obj
    return jsobj2pyobj(obj)
}

Test runner

Ready to run.

Testing in
TestOps/sec
no cache
jsobj2pyobj(obj)
ready
in cache
cache(obj)
ready
no in cache
cache(obj2)
ready
array
jsobj2pyobj(arr)
ready
cache array
cache(arr)
ready

Revisions

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