As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label JSON. Show all posts

I want to see the performance between with and without C extension. I downloaded the latest 2.1.3 version. And make three builds using Python 2.6.6:

  1. rm -rf build ; python setup.py build && rm build/lib*/simplejson/_speedups.so
  2. rm -rf build ; python setup.py build
  3. rm -rf build ; CFLAGS="-march=core2 -O2 -pipe -fomit-frame-pointer" python setup.py build

The first one removes the compiled C extension, the second one is normal, then third one uses the current CFLAGS I use in emerge. And the following lines is how C extensions got compiled:

Without customized CFLAGS
x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/usr/include/python2.6 -c simplejson/_speedups.c -o build/temp.linux-x86_64-2.6/simplejson/_speedups.o
x86_64-pc-linux-gnu-gcc -pthread -shared build/temp.linux-x86_64-2.6/simplejson/_speedups.o -L/usr/lib64 -lpython2.6 -o build/lib.linux-x86_64-2.6/simplejson/_speedups.so

With customized CFLAGS
x86_64-pc-linux-gnu-gcc -pthread -march=core2 -O2 -pipe -fomit-frame-pointer -fPIC -I/usr/include/python2.6 -c simplejson/_speedups.c -o build/temp.linux-x86_64-2.6/simplejson/_speedups.o
x86_64-pc-linux-gnu-gcc -pthread -shared -march=core2 -O2 -pipe -fomit-frame-pointer build/temp.linux-x86_64-2.6/simplejson/_speedups.o -L/usr/lib64 -lpython2.6 -o build/lib.linux-x86_64-2.6/

I use the following code to do the test,

import timeit
t = timeit.Timer('json.loads(json_str)', 'import simplejson as json;json_str=open("test.json","r").read()')
print t.timeit(100)

The test.json is http://googleblog.blogspot.com/feeds/posts/default?alt=json&max-results=500, over 3 MB, 500 entires.

The results is:

Tests Elapsed time for 100 loads()
Without C extension 126.230s
json 1.9 in Python 2.6.6 060.616s
With C extension 009.945s
With C extension (CFLAGS) 007.555s

With C extension is at least 10 times faster. I also put the simplejson 1.9 which in Python 2.6.6 in the result. Without extension, 1.9 -> 2.1.3, twice more slower. I didnt download simplejson 1.9 to double check, but I dont think its modified for being shipped with Python.

localStorage is a feature of HTML5s Web Storage. You can store or retrieve as the followings:

localStorage[key] = value;
value = localStorage[key];
delete localStorage[key];

localStorage.setItem(key, value);
value = localStorage.getItem(key);
localStorage.removeItem(key);

localStorage.key = value;
value = localStorage.key;
delete localStorage.key;

You can list:

for (key in localStorage)
  console.log(key, localStorage[key]);

You can clean up at once:

localStorage.clear();

You can put every thing in but you might not get what you put in, because

The setItem(key, value) method must first create a structured clone of the given value. If this raises an exception, then the exception must be thrown and the list associated with the object is left unchanged. If constructing the structured clone would involve constructing a new ImageData object, then throw a NOT_SUPPORTED_ERR exception instead.