~ubuntu-branches/ubuntu/natty/pytables/natty-updates

« back to all changes in this revision

Viewing changes to bench/searchsorted-bench.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2006-06-28 10:45:03 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060628104503-qsoprcycf84lql5h
Tags: 1.3.2-2
  * Fixed call to pyversions in debian/rules which failed on recent versions 
    of pyversions
  * Fixed clean rule in debian/rules which left the stamp files behind
  * Acknowledge NMU
  * Added Alexandre Fayolle to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        table.row['var2'] = i
45
45
        table.row['var3'] = i
46
46
        #table.row['var4'] = i % 2
47
 
        table.row['var4'] = i > 2
 
47
        #table.row['var4'] = i > 2
48
48
        table.row.append()
49
49
    rowswritten += nrows
50
50
    table.flush()
51
51
    rowsize = table.rowsize
52
52
    indexrows = 0
53
 
        
 
53
 
54
54
    # Index one entry:
55
55
    if index:
56
56
        if atom == "string":
67
67
            print "Number of indexed rows:", indexrows
68
68
    # Close the file (eventually destroy the extended type)
69
69
    fileh.close()
70
 
    
 
70
 
71
71
    return (rowswritten, rowsize)
72
72
 
73
73
def readFile(filename, atom, niter, verbose):
122
122
#                    for i in table.where(3<=table.cols.var3 < 5.)]
123
123
#             results = [(p.nrow(), p["var3"])
124
124
#                        for p in table.where(1000.-i<=table.cols.var3<1000.+i)]
125
 
            results = [p["var3"] # (p.nrow(), p["var3"]) 
 
125
            results = [p["var3"] # (p.nrow(), p["var3"])
126
126
                       for p in table.where(100*i<=table.cols.var3<100*(i+1))]
127
127
#                        for p in table
128
128
#                        if 100*i<=p["var3"]<100*(i+1)]
136
136
        print results
137
137
 
138
138
    rowsread = table.nrows * niter
139
 
    rowsize = table.rowsize 
140
 
        
 
139
    rowsize = table.rowsize
 
140
 
141
141
    # Close the file (eventually destroy the extended type)
142
142
    fileh.close()
143
143
 
177
177
    if verbose:
178
178
        print "Values that fullfill the conditions:"
179
179
        print results
180
 
        
 
180
 
181
181
    # Close the file (eventually destroy the extended type)
182
182
    fileh.close()
183
183
 
192
192
        psyco_imported = 1
193
193
    except:
194
194
        psyco_imported = 0
195
 
    
 
195
 
196
196
    import time
197
 
    
 
197
 
198
198
    usage = """usage: %s [-v] [-p] [-R range] [-r] [-w] [-s recsize ] [-a
199
199
    atom] [-c level] [-l complib] [-S] [-F] [-i item] [-n nrows] [-x]
200
200
    [-k niter] file
201
201
            -v verbose
202
 
            -p use "psyco" if available
 
202
            -p use "psyco" if available
203
203
            -R select a range in a field in the form "start,stop,step"
204
 
            -r only read test
205
 
            -w only write test
 
204
            -r only read test
 
205
            -w only write test
206
206
            -s record size
207
207
            -a use [float], [int], [bool] or [string] atom
208
208
            -c sets a compression level (do not set it or 0 for no compression)
221
221
        sys.exit(0)
222
222
 
223
223
    # if we pass too much parameters, abort
224
 
    if len(pargs) <> 1: 
 
224
    if len(pargs) <> 1:
225
225
        sys.stderr.write(usage)
226
226
        sys.exit(0)
227
227
 
278
278
            nrows = int(option[1])
279
279
        elif option[0] == '-k':
280
280
            niter = int(option[1])
281
 
            
 
281
 
282
282
    # Build the Filters instance
283
283
    filters = Filters(complevel=complevel, complib=complib,
284
284
                      shuffle=shuffle, fletcher32=fletcher32)
292
292
            print "Compression library:", complib
293
293
            if shuffle:
294
294
                print "Suffling..."
295
 
        t1 = time.time()
296
 
        cpu1 = time.clock()
 
295
        t1 = time.time()
 
296
        cpu1 = time.clock()
297
297
        if psyco_imported and usepsyco:
298
298
            psyco.bind(createFile)
299
 
        (rowsw, rowsz) = createFile(file, nrows, filters,
 
299
        (rowsw, rowsz) = createFile(file, nrows, filters,
300
300
                                    atom, recsize, index, verbose)
301
 
        t2 = time.time()
 
301
        t2 = time.time()
302
302
        cpu2 = time.clock()
303
 
        tapprows = round(t2-t1, 3)
304
 
        cpuapprows = round(cpu2-cpu1, 3)
 
303
        tapprows = round(t2-t1, 3)
 
304
        cpuapprows = round(cpu2-cpu1, 3)
305
305
        tpercent = int(round(cpuapprows/tapprows, 2)*100)
306
 
        print "Rows written:", rowsw, " Row size:", rowsz
307
 
        print "Time writing rows: %s s (real) %s s (cpu)  %s%%" % \
 
306
        print "Rows written:", rowsw, " Row size:", rowsz
 
307
        print "Time writing rows: %s s (real) %s s (cpu)  %s%%" % \
308
308
              (tapprows, cpuapprows, tpercent)
309
 
        print "Write rows/sec: ", int(rowsw / float(tapprows))
310
 
        print "Write KB/s :", int(rowsw * rowsz / (tapprows * 1024))
311
 
        
 
309
        print "Write rows/sec: ", int(rowsw / float(tapprows))
 
310
        print "Write KB/s :", int(rowsw * rowsz / (tapprows * 1024))
 
311
 
312
312
    if testread:
313
313
        if psyco_imported and usepsyco:
314
314
            psyco.bind(readFile)
315
315
            psyco.bind(searchFile)
316
 
        t1 = time.time()
 
316
        t1 = time.time()
317
317
        cpu1 = time.clock()
318
318
        if rng or item:
319
319
            (rowsr, uncomprB, niter) = searchFile(file, atom, verbose, item)
320
320
        else:
321
321
            for i in range(1):
322
322
                (rowsr, rowsel, rowsz) = readFile(file, atom, niter, verbose)
323
 
        t2 = time.time()
 
323
        t2 = time.time()
324
324
        cpu2 = time.clock()
325
 
        treadrows = round(t2-t1, 3)
 
325
        treadrows = round(t2-t1, 3)
326
326
        cpureadrows = round(cpu2-cpu1, 3)
327
327
        tpercent = int(round(cpureadrows/treadrows, 2)*100)
328
328
        tMrows = rowsr/(1000*1000.)
329
329
        sKrows = rowsel/1000.
330
 
        print "Rows read:", rowsr, "Mread:", round(tMrows, 3), "Mrows"
331
 
        print "Rows selected:", rowsel, "Ksel:", round(sKrows,3), "Krows"
332
 
        print "Time reading rows: %s s (real) %s s (cpu)  %s%%" % \
 
330
        print "Rows read:", rowsr, "Mread:", round(tMrows, 3), "Mrows"
 
331
        print "Rows selected:", rowsel, "Ksel:", round(sKrows,3), "Krows"
 
332
        print "Time reading rows: %s s (real) %s s (cpu)  %s%%" % \
333
333
              (treadrows, cpureadrows, tpercent)
334
 
        print "Read Mrows/sec: ", round(tMrows / float(treadrows), 3)
335
 
        #print "Read KB/s :", int(rowsr * rowsz / (treadrows * 1024))
336
 
#       print "Uncompr MB :", int(uncomprB / (1024 * 1024))
337
 
#       print "Uncompr MB/s :", int(uncomprB / (treadrows * 1024 * 1024))
338
 
#       print "Total chunks uncompr :", int(niter)
339
 
    
 
334
        print "Read Mrows/sec: ", round(tMrows / float(treadrows), 3)
 
335
        #print "Read KB/s :", int(rowsr * rowsz / (treadrows * 1024))
 
336
#       print "Uncompr MB :", int(uncomprB / (1024 * 1024))
 
337
#       print "Uncompr MB/s :", int(uncomprB / (treadrows * 1024 * 1024))
 
338
#       print "Total chunks uncompr :", int(niter)