File: serialization-benchmark.py

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (30 lines) | stat: -rw-r--r-- 859 bytes parent folder | download | duplicates (2)
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
import time
# change this line to load your reference simulation
O.load2('ref.boost.bin.gz')
base = '~sim~'


# http://blogmag.net/blog/read/38/Print_human_readable_file_size
def sizeof_fmt(num):
	for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
		if num < 1024.0:
			return "%3.1f%s" % (num, x)
		num /= 1024.0


def io(ext, load, noBoost=False):
	t0 = time.time()
	f = base + ('.yade.' if noBoost else '.boost.') + ext
	((O.load if noBoost else O.load2) if load else (O.save if noBoost else O.save2))(f)
	print(
	        ('Loaded' if load else 'Saved '), ('yade ' if noBoost else 'boost'), '%-7s ' % ext, '%7s' % sizeof_fmt(os.path.getsize(f)),
	        '%.1fs' % (time.time() - t0)
	)


for ext in ['xml', 'xml.bz2']:
	io(ext, False, True)
	io(ext, True, True)
for ext in ['xml', 'xml.gz', 'xml.bz2', 'bin', 'bin.gz', 'bin.bz2']:
	io(ext, False)
	io(ext, True)