-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbench.py
More file actions
25 lines (21 loc) · 690 Bytes
/
bench.py
File metadata and controls
25 lines (21 loc) · 690 Bytes
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
import time
import csv
import cbor
# Get a source dataset
places={}
with open("kx-nz-place-names-nzgb-CSV/nz-place-names-nzgb.csv") as f:
src_data = csv.DictReader(f)
for row in src_data:
places[row['name']] = {'id': int(row['feat_id']), 'X': float(row['ref_point_X']), 'Y': float(row['ref_point_Y'])}
print("Places: %d" % len(places))
# Encode into cbor
start = time.time()
cbor_data = cbor.dumps(places)
print('Encoding time: %f' % (time.time()-start))
# Write out (for C++)
with open("cbor-python-wrote", 'wb') as f:
f.write(cbor_data)
# Parse back to source
start = time.time()
cbor_original = cbor.loads(cbor_data)
print('Parse time: %f' % (time.time()-start))