|
2 | 2 |
|
3 | 3 | from rootpy.io import TemporaryFile
|
4 | 4 | import rootpy
|
5 |
| -from root_numpy import array2tree |
| 5 | +from root_numpy import array2tree, tree2array |
6 | 6 | import numpy as np
|
7 | 7 | import uuid
|
8 | 8 | import random
|
|
27 | 27 | def randomword(length):
|
28 | 28 | return ''.join(random.choice(string.lowercase) for i in range(length))
|
29 | 29 |
|
30 |
| -def make_tree(entries, branches=10, dtype=np.double): |
| 30 | +def make_tree(entries, branches=1, dtype=np.double): |
31 | 31 | dtype = np.dtype([(randomword(20), dtype) for idx in range(branches)])
|
32 | 32 | array = np.zeros(entries, dtype=dtype)
|
33 | 33 | return array2tree(array, name=uuid.uuid4().hex)
|
34 | 34 |
|
| 35 | +# warm up |
| 36 | +print("warming up... ", end="") |
| 37 | +for i in range(30): |
| 38 | + tree = make_tree(100, branches=1) |
| 39 | + branchname = tree.GetListOfBranches()[0].GetName() |
| 40 | + tree2array(tree) |
| 41 | + tree.Draw(branchname, "", "goff") |
| 42 | +print("done\n") |
| 43 | + |
35 | 44 | # time vs entries
|
36 | 45 | num_entries = np.logspace(1, 7, 20, dtype=np.int)
|
37 | 46 | root_numpy_times = []
|
@@ -73,18 +82,19 @@ def make_tree(entries, branches=10, dtype=np.double):
|
73 | 82 | num_branches = np.linspace(1, 10, 10, dtype=np.int)
|
74 | 83 | root_numpy_times = []
|
75 | 84 | root_times = []
|
| 85 | +iterations = 10 |
76 | 86 | print("\n{0:>10} {1:<10} {2:<10}".format("branches", "root_numpy", "ROOT"))
|
77 | 87 | for branches in num_branches:
|
78 | 88 | print("{0:>10}".format(branches), end="")
|
79 | 89 | tree = make_tree(1000000, branches=branches)
|
80 | 90 | branchnames = [branch.GetName() for branch in tree.GetListOfBranches()]
|
81 | 91 | branchname = ':'.join(branchnames)
|
82 |
| - iterations = 5 |
83 | 92 | root_numpy_times.append(
|
84 | 93 | min(timeit.Timer('tree2array(tree)',
|
85 | 94 | setup='from root_numpy import tree2array; from __main__ import tree').repeat(3, iterations)) / iterations)
|
| 95 | + opt = 'candle' if branches > 1 else '' |
86 | 96 | root_times.append(
|
87 |
| - min(timeit.Timer('draw("{0}", "", "goff candle")'.format(branchname), |
| 97 | + min(timeit.Timer('draw("{0}", "", "goff {1}")'.format(branchname, opt), |
88 | 98 | setup='from __main__ import tree; draw = tree.Draw').repeat(3, iterations)) / iterations)
|
89 | 99 | print(" {0:10.5f}".format(root_numpy_times[-1]), end="")
|
90 | 100 | print(" {0:10.5f}".format(root_times[-1]))
|
|
0 commit comments