chunkshape bench.py :  » Database » PyTables » tables-2.1.2 » bench » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » PyTables 
PyTables » tables 2.1.2 » bench » chunkshape-bench.py
#!/usr/bin/env python
# Benchmark the effect of chunkshapes in reading large datasets.
# You need at least PyTables 2.1 to run this!
# F. Alted

import numpy, tables
from time import time

dim1, dim2 = 360, 6109666
rows_to_read = range(0, 360, 36)

print "="*32
# Create the EArray
f = tables.openFile("/tmp/test.h5", "w")
a = f.createEArray(f.root, "a", tables.Float64Atom(), shape = (dim1, 0),
                   expectedrows=dim2)
print "Chunkshape for original array:", a.chunkshape

# Fill the EArray
t1 = time()
zeros = numpy.zeros((dim1,1), dtype="float64")
for i in xrange(dim2):
    a.append(zeros)
tcre = round(time()-t1, 3)
thcre = round(dim1*dim2*8 / (tcre * 1024 * 1024), 1)
print "Time to append %d rows: %s sec (%s MB/s)" % (a.nrows, tcre, thcre)

# Read some row vectors from the original array
t1 = time()
for i in rows_to_read: r1 = a[i,:]
tr1 = round(time()-t1, 3)
thr1 = round(dim2*len(rows_to_read)*8 / (tr1 * 1024 * 1024), 1)
print "Time to read ten rows in original array: %s sec (%s MB/s)" % (tr1, thr1)

print "="*32
# Copy the array to another with a row-wise chunkshape
t1 = time()
#newchunkshape = (1, a.chunkshape[0]*a.chunkshape[1])
newchunkshape = (1, a.chunkshape[0]*a.chunkshape[1]*10)  # ten times larger
b = a.copy(f.root, "b", chunkshape=newchunkshape)
tcpy = round(time()-t1, 3)
thcpy = round(dim1*dim2*8 / (tcpy * 1024 * 1024), 1)
print "Chunkshape for row-wise chunkshape array:", b.chunkshape
print "Time to copy the original array: %s sec (%s MB/s)" % (tcpy, thcpy)

# Read the same ten rows from the new copied array
t1 = time()
for i in rows_to_read: r2 = b[i,:]
tr2 = round(time()-t1, 3)
thr2 = round(dim2*len(rows_to_read)*8 / (tr2 * 1024 * 1024), 1)
print "Time to read with a row-wise chunkshape: %s sec (%s MB/s)" % (tr2, thr2)
print "="*32
print "Speed-up with a row-wise chunkshape:", round(tr1/tr2, 1)

f.close()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.