JSON.stringify vs no

Benchmark created by Enzo on


Setup

a=1234
    b='mystring'
    c=[1,2,3]
    d={a:1,b:2,c:3}
    
    function to1(v) {
        return JSON.stringify(v);
    }
    
    function to2(v) {
        var type = typeof v;
        if (type === 'object' || type === 'array')
            return JSON.stringify(v);
        else if (type === 'string')
            return '"' + v + '"';
        else
            return v;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
With
to1(a)
to1(b)
to1(c)
to1(d)
ready
Without
to2(a)
to2(b)
to2(c)
to2(d)
ready

Revisions

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

  • Revision 1: published by Enzo on