recarray2 test.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 » recarray2-test.py
import sys, time, os
import numarray as num
import chararray
import recarray
import recarray2  # This is my modified version

usage = \
"""usage: %s recordlength
     Set recordlength to 1000 at least to obtain decent figures!
""" % sys.argv[0]

try:
    reclen = int(sys.argv[1])
except:
    print usage
    sys.exit()

delta = 0.000001

# Creation of recarrays objects for test
x1=num.array(num.arange(reclen))
x2=chararray.array(None, itemsize=7, shape=reclen)
x3=num.array(num.arange(reclen,reclen*3,2), num.Float64)
r1=recarray.fromarrays([x1,x2,x3],names='a,b,c')
r2=recarray2.fromarrays([x1,x2,x3],names='a,b,c')

print "recarray shape in test ==>", r2.shape

print "Assignment in recarray original"
print "-------------------------------"
t1 = time.clock()
for row in xrange(reclen):
    #r1.field("b")[row] = "changed"
    r1.field("c")[row] = float(row**2)
t2 = time.clock()
origtime = round(t2-t1, 3)
print "Assign time:", origtime, " Rows/s:", int(reclen/(origtime+delta))
#print "Field b on row 2 after re-assign:", r1.field("c")[2]
print

print "Assignment in recarray modified"
print "-------------------------------"
t1 = time.clock()
for row in xrange(reclen):
    rec = r2._row(row)  # select the row to be changed
    #rec.b = "changed"      # change the "b" field
    rec.c = float(row**2)  # Change the "c" field
t2 = time.clock()
ttime = round(t2-t1, 3)
print "Assign time:", ttime, " Rows/s:", int(reclen/(ttime+delta)),
print " Speed-up:", round(origtime/ttime,3)
#print "Field b on row 2 after re-assign:", r2.field("c")[2]
print

print "Selection in recarray original"
print "------------------------------"
t1 = time.clock()
for row in xrange(reclen):
    rec = r1[row]
    if rec.field("a") < 3:
        print "This record pass the cut ==>", rec.field("c"), "(row", row, ")"
t2 = time.clock()
origtime = round(t2-t1, 3)
print "Select time:", origtime, " Rows/s:", int(reclen/(origtime+delta))
print

print "Selection in recarray modified"
print "------------------------------"
t1 = time.clock()
for row in xrange(reclen):
    rec = r2._row(row)
    if rec.a < 3:
        print "This record pass the cut ==>", rec.c, "(row", row, ")"
t2 = time.clock()
ttime = round(t2-t1, 3)
print "Select time:", ttime, " Rows/s:", int(reclen/(ttime+delta)),
print " Speed-up:", round(origtime/ttime,3)
print

print "Printing in recarray original"
print "------------------------------"
f = open("test.out","w")
t1 = time.clock()
f.write(str(r1))
t2 = time.clock()
origtime = round(t2-t1, 3)
f.close()
os.unlink("test.out")
print "Print time:", origtime, " Rows/s:", int(reclen/(origtime+delta))
print
print "Printing in recarray modified"
print "------------------------------"
f = open("test2.out","w")
t1 = time.clock()
f.write(str(r2))
t2 = time.clock()
ttime = round(t2-t1, 3)
f.close()
os.unlink("test2.out")
print "Print time:", ttime, " Rows/s:", int(reclen/(ttime+delta)),
print " Speed-up:", round(origtime/ttime,3)
print
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.