getvaluebykey

JavaScript performance comparison

Revision 2 of this test case created

Info

getting values by keys

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
String
var obj = {"callbackId":0,"code":1,"data":[[[{"key":"Valid","value":"13022013 08:00"},{"key":"Exp","value":"13022013 23:00"},{"key":"ProductName","value":" "},{"key":"PartyType","value":"AD"},{"key":"UsedLoc","value":" "},{"key":"IPE","value":"23"},{"key":"Class","value":"3"},{"key":"Orig","value":"208"},{"key":"OrigLoce","value":"    "},{"key":"Dest","value":"208"},{"key":"DestLoce","value":"    "},{"key":"PartySize","value":"1"},{"key":"Route","value":" "},{"key":"Remaining","value":"0"},{"key":"TransType","value":"-1"},{"key":"TST","value":"0"}],[{"key":"Valid","value":"13022013 08:00"},{"key":"Exp","value":"13022013 23:00"},{"key":"ProductName","value":" "},{"key":"PartyType","value":"AD"},{"key":"UsedLoc","value":" "},{"key":"IPE","value":"23"},{"key":"Class","value":"3"},{"key":"Orig","value":"0"},{"key":"OrigLoce","value":"0"},{"key":"Dest","value":"208"},{"key":"DestLoce","value":"    "},{"key":"PartySize","value":"1"},{"key":"Route","value":" "},{"key":"Remaining","value":"0"},{"key":"TransType","value":"-1"},{"key":"TST","value":"0"}],[{"key":"Valid","value":"13022013 08:00"},{"key":"Exp","value":"13022013 23:00"},{"key":"ProductName","value":" "},{"key":"PartyType","value":"AD"},{"key":"UsedLoc","value":" "},{"key":"IPE","value":"23"},{"key":"Class","value":"3"},{"key":"Orig","value":"208"},{"key":"OrigLoce","value":"    "},{"key":"Dest","value":"208"},{"key":"DestLoce","value":"    "},{"key":"PartySize","value":"1"},{"key":"Route","value":" "},{"key":"Remaining","value":"-1"},{"key":"TransType","value":"-1"},{"key":"TST","value":"0"}]]],"responseType":12,"timestamp":1290,"type":"itso"}

        function getValByKeyString(obj,key)
        {
return "";
                var result = "";
                var str = JSON.stringify(obj);
               
                var piece1 = str.split('{"key":"'+key+'","value":"');
               
                if(piece1.length == 1)
                return "empty";
               
                var piece2 = piece1[1].split('"}')[0];
               
                return piece2+"";
        }

getValByKeyString(obj,"TransType");
pending…
Object
var obj = {"callbackId":0,"code":1,"data":[[[{"key":"Valid","value":"13022013 08:00"},{"key":"Exp","value":"13022013 23:00"},{"key":"ProductName","value":" "},{"key":"PartyType","value":"AD"},{"key":"UsedLoc","value":" "},{"key":"IPE","value":"23"},{"key":"Class","value":"3"},{"key":"Orig","value":"208"},{"key":"OrigLoce","value":"    "},{"key":"Dest","value":"208"},{"key":"DestLoce","value":"    "},{"key":"PartySize","value":"1"},{"key":"Route","value":" "},{"key":"Remaining","value":"0"},{"key":"TransType","value":"-1"},{"key":"TST","value":"0"}],[{"key":"Valid","value":"13022013 08:00"},{"key":"Exp","value":"13022013 23:00"},{"key":"ProductName","value":" "},{"key":"PartyType","value":"AD"},{"key":"UsedLoc","value":" "},{"key":"IPE","value":"23"},{"key":"Class","value":"3"},{"key":"Orig","value":"0"},{"key":"OrigLoce","value":"0"},{"key":"Dest","value":"208"},{"key":"DestLoce","value":"    "},{"key":"PartySize","value":"1"},{"key":"Route","value":" "},{"key":"Remaining","value":"0"},{"key":"TransType","value":"-1"},{"key":"TST","value":"0"}],[{"key":"Valid","value":"13022013 08:00"},{"key":"Exp","value":"13022013 23:00"},{"key":"ProductName","value":" "},{"key":"PartyType","value":"AD"},{"key":"UsedLoc","value":" "},{"key":"IPE","value":"23"},{"key":"Class","value":"3"},{"key":"Orig","value":"208"},{"key":"OrigLoce","value":"    "},{"key":"Dest","value":"208"},{"key":"DestLoce","value":"    "},{"key":"PartySize","value":"1"},{"key":"Route","value":" "},{"key":"Remaining","value":"-1"},{"key":"TransType","value":"-1"},{"key":"TST","value":"0"}]]],"responseType":12,"timestamp":1290,"type":"itso"}

function getValByKey(obj,key)
{
        var result = "";
        for(var i=0; i<obj.length; i++)
        {
                if(obj[i].key==key)
                result =  obj[i].value;
        }
        return result+"";
}


getValByKey(obj.data,"TransType");
 
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