Discussion List Archives

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CIF-JSON new draft

Marcin,

Right, OK. Here it is with a 1,000,000 element array of random strings or numbers.

Does this code look better? Each includes JSON parsing of the array, which either has strings or numbers. The first also requires, then, parsing of the floats upon use.

var c = 0
a = "[0"
for (var i = 0; i < 1000000; i++)
 a += ',"' + Math.random() + '"';
a +=  "]"

x = "[0"
for (var i = 0; i < 1000000; i++)
 x+= "," + Math.random();
x += "]"

for (j = 1; j < 5; j++) {
    t = +new Date;
    b = JSON.parse(a);
    for (var i = 0; i < 1000000; i++) {   
      c = parseFloat(b[i]);
    }
    t = +new Date - t;
    document.write(t + " ms parseFloat(JSON.parse([str,str,str...]))<br>");
}
document.write("<br>")
for (j = 1; j < 5; j++) {
    t = +new Date;
    d = JSON.parse(x);
    for (var i = 0; i < 1000000; i++) {
      c = d[i];
    }
    t = +new Date - t;
    document.write(t + " ms JSON.parse([num,num,num,num])<br>");
}


652 ms parseFloat(JSON.parse([str,str,str...]))
621 ms parseFloat(JSON.parse([str,str,str...]))
620 ms parseFloat(JSON.parse([str,str,str...]))
618 ms parseFloat(JSON.parse([str,str,str...]))

601 ms JSON.parse([num,num,num,num])
570 ms JSON.parse([num,num,num,num])
578 ms JSON.parse([num,num,num,num])
569 ms JSON.parse([num,num,num,num])

In my mind this is not a significant difference. 


​Bob
_______________________________________________
cif-developers mailing list
cif-developers@iucr.org
http://mailman.iucr.org/cgi-bin/mailman/listinfo/cif-developers

Reply to: [list | sender only]
International Union of Crystallography

Scientific Union Member of the International Council for Science (admitted 1947). Member of CODATA, the ICSU Committee on Data. Member of ICSTI, the International Council for Scientific and Technical Information. Partner with UNESCO, the United Nations Educational, Scientific and Cultural Organization in the International Year of Crystallography 2014.

ICSU Scientific Freedom Policy

The IUCr observes the basic policy of non-discrimination and affirms the right and freedom of scientists to associate in international scientific activity without regard to such factors as ethnic origin, religion, citizenship, language, political stance, gender, sex or age, in accordance with the Statutes of the International Council for Science.