Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.
File test.py,
1.6 KB
(added by jmoore, 13 years ago) |
File used to test various read times.
|
Line | |
---|
1 | import time |
---|
2 | try: |
---|
3 | client.sf |
---|
4 | except: |
---|
5 | import omero |
---|
6 | client = omero.client("localhost") |
---|
7 | client.createSession("root","ome") |
---|
8 | |
---|
9 | import logging |
---|
10 | logging.basicConfig(level=00) |
---|
11 | |
---|
12 | |
---|
13 | from omero.util.decorators import timeit, perf |
---|
14 | |
---|
15 | |
---|
16 | def timeit(msg, f): |
---|
17 | try: |
---|
18 | start = time.time() |
---|
19 | return f() |
---|
20 | finally: |
---|
21 | stop = time.time() |
---|
22 | print msg, stop-start |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | sr = client.sf.sharedResources() |
---|
27 | t = timeit("open", lambda: sr.openTable(omero.model.OriginalFileI(1203, False))) |
---|
28 | cols = timeit("headers", t.getHeaders) |
---|
29 | #timeit("read", lambda: t.read(range(len(cols)), 0, 4000)) |
---|
30 | |
---|
31 | NC = len(cols) |
---|
32 | NR = 4000 |
---|
33 | PCT = (.1, .25, .5, .75, .9, 1) |
---|
34 | PCT = (.33, .66, 1) |
---|
35 | C = [int(NC*x) for x in PCT] |
---|
36 | R = [int(NR*x) for x in PCT] |
---|
37 | |
---|
38 | fmtc = "%4s\t" |
---|
39 | fmt = "%4.2f\t" |
---|
40 | print " \t", |
---|
41 | for c in C: |
---|
42 | print fmtc % c, |
---|
43 | print |
---|
44 | |
---|
45 | def run_once(c, r): |
---|
46 | """ |
---|
47 | Run a single batch and return the time. |
---|
48 | """ |
---|
49 | start = time.time() |
---|
50 | t.read(range(c), 0, r) |
---|
51 | stop = time.time() |
---|
52 | return stop - start |
---|
53 | |
---|
54 | def batch(size, max): |
---|
55 | current = 0 |
---|
56 | rv = [] |
---|
57 | while current < max: |
---|
58 | rv.append(current) |
---|
59 | current += 1 |
---|
60 | if len(rv) == size: |
---|
61 | yield rv |
---|
62 | rv = [] |
---|
63 | |
---|
64 | def run_batches(c_batch, r_batch): |
---|
65 | """ |
---|
66 | Run a single batch and return the time. |
---|
67 | """ |
---|
68 | elapsed = 0 |
---|
69 | for r in batch(r_batch, NR): |
---|
70 | for c in batch(c_batch, NC): |
---|
71 | start = time.time() |
---|
72 | t.read(c, r[0], r[-1]) |
---|
73 | stop = time.time() |
---|
74 | elapsed += (stop-start) |
---|
75 | return elapsed |
---|
76 | |
---|
77 | run = run_batches |
---|
78 | |
---|
79 | for r in R: |
---|
80 | print fmtc % r, |
---|
81 | for c in C: |
---|
82 | elapsed = run(c, r) |
---|
83 | print fmt % elapsed, |
---|
84 | print |
---|
Download in other formats:
1.3.13-PRO © 2008-2011
Agilo Software all
rights reserved
(this page was served in: 0.30284 sec.)