Created
December 23, 2016 23:38
-
-
Save inokappa/ad27a544d6c40ca845f9f889213b2b1d to your computer and use it in GitHub Desktop.
json モジュールの速度比較(Python 2 系)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from timer import Timer | |
import csv | |
import json | |
import simplejson | |
import ujson | |
JSON_FILE='dummy_1000.json' | |
CSV_FILE='dummy_1000.csv' | |
print 'decode -----------------------------------------------' | |
with open(JSON_FILE) as f: | |
with Timer() as t: | |
data = json.load(f) | |
print '%s' % t.secs | |
# print '=> elasped json : %s s' % t.secs | |
with open(JSON_FILE) as f: | |
with Timer() as t: | |
data = simplejson.load(f) | |
print '%s' % t.secs | |
# print '=> elasped simplejson : %s s' % t.secs | |
with open(JSON_FILE) as f: | |
with Timer() as t: | |
data = ujson.load(f) | |
print '%s' % t.secs | |
# print '=> elasped ujson : %s s' % t.secs | |
print 'encode -----------------------------------------------' | |
with open(CSV_FILE) as f: | |
with Timer() as t: | |
result = [] | |
for line in csv.DictReader(f): | |
line_json = json.dumps(line) | |
result.append(line_json) | |
print '%s' % t.secs | |
# print '=> elasped json : %s s' % t.secs | |
with open(CSV_FILE) as f: | |
with Timer() as t: | |
result = [] | |
for line in csv.DictReader(f): | |
line_json = simplejson.dumps(line) | |
result.append(line_json) | |
print '%s' % t.secs | |
# print '=> elasped simplejson : %s s' % t.secs | |
with open(CSV_FILE) as f: | |
with Timer() as t: | |
result = [] | |
for line in csv.DictReader(f): | |
line_json = ujson.dumps(line) | |
result.append(line_json) | |
print '%s' % t.secs | |
# print '=> elasped ujson : %s s' % t.secs |
Author
inokappa
commented
Dec 23, 2016
•
- timer.py
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment