Repository navigation
Expand file tree
/
Copy pathbench_dump.py
More file actions
75 lines (58 loc) · 1.87 KB
/
Copy pathbench_dump.py
File metadata and controls
75 lines (58 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2011 yinhm
import datetime
import h5py
import os
import shelve
import sys
import timeit
import cPickle as pickle
import numpy as np
ROOT_PATH = os.path.join(os.path.realpath(os.path.dirname(__file__)), '..')
sys.path[0:0] = [ROOT_PATH]
from cStringIO import StringIO
from datafeed.client import Client
from datafeed.datastore import *
from datafeed.exchange import *
from datafeed.providers.dzh import *
var_path = os.path.join(ROOT_PATH, 'var')
store = Manager('/tmp/df', SH())
filename = os.path.join(var_path, "20101202.h5")
date = datetime.datetime.strptime('20101202', '%Y%m%d').date()
hdf_store = h5py.File(filename)
f1 = NumpyFile(hdf_store, date, SH().market_minutes)
f2 = shelve.open('/tmp/dump.shelve')
def f1_bench_read():
for k, v in hdf_store.iteritems():
if isinstance(v, h5py.Group):
continue
f1[str(k)] = v[:]
def f1_bench_dump():
pickle.dump(f1, open('/tmp/dump.pickle', 'wb'), -1)
def f2_bench_read():
for k, v in hdf_store.iteritems():
if isinstance(v, h5py.Group):
continue
f2[str(k)] = v[:]
def f2_bench_dump():
f2.close()
if __name__ == '__main__':
d = 1
timer = timeit.Timer(stmt='f1_bench_read()',
setup="from __main__ import f1_bench_read")
result = timer.timeit(number=d)
print result
timer = timeit.Timer(stmt='f1_bench_dump()',
setup="from __main__ import f1_bench_dump")
result = timer.timeit(number=d)
print result
timer = timeit.Timer(stmt='f2_bench_read()',
setup="from __main__ import f2_bench_read")
result = timer.timeit(number=d)
print result
timer = timeit.Timer(stmt='f2_bench_dump()',
setup="from __main__ import f2_bench_dump")
result = timer.timeit(number=d)
print result