1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
import time
import numpy
import ROOT
import root_numpy
import awkward
import awkward1
import uproot
from uproot import asgenobj, asdtype, STLVector
num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged0.root")["jagged0"]["branch"]
for i in range(branch.numbaskets):
result = branch.basket(i)
num += len(result)
walltime = time.time() - starttime
print("TTree uproot jagged0\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
file = ROOT.TFile("data/sample-jagged0.root")
tree = file.Get("jagged0")
starttime = time.time()
for i in range(branch.numbaskets):
result = root_numpy.tree2array(tree, "branch", start=branch.basket_entrystart(i), stop=branch.basket_entrystop(i))
walltime = time.time() - starttime
print("TTree root_numpy jagged0\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged1.root")["jagged1"]["branch"]
for i in range(branch.numbaskets):
result = branch.basket(i)
num += len(result.content)
walltime = time.time() - starttime
print("TTree OLD jagged1\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged1.root")["jagged1"]["branch"]
for i in range(branch.numbaskets):
jagged = branch.basket(i, uproot.asdebug)
byteoffsets = awkward1.layout.Index64(jagged.offsets)
rawdata = awkward1.layout.NumpyArray(jagged.content[6:])
result = awkward1.layout.fromroot_nestedvector(byteoffsets, rawdata, 1, numpy.dtype(">f").itemsize, ">f")
q = numpy.asarray(result.content).astype("<f")
num += len(result.content)
walltime = time.time() - starttime
print("TTree NEW jagged1\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
file = ROOT.TFile("data/sample-jagged1.root")
tree = file.Get("jagged1")
starttime = time.time()
for i in range(branch.numbaskets):
result = root_numpy.tree2array(tree, "branch", start=branch.basket_entrystart(i), stop=branch.basket_entrystop(i))
walltime = time.time() - starttime
print("TTree root_numpy jagged1\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged2.root")["jagged2"]["branch"]
for i in range(5):
jagged = branch.basket(i)
q = awkward.fromiter(jagged)
num += len(q.content.content)
walltime = time.time() - starttime
print("TTree OLD jagged2\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged2.root")["jagged2"]["branch"]
for i in range(5):
jagged = branch.basket(i, uproot.asdebug)
byteoffsets = awkward1.layout.Index64(jagged.offsets)
rawdata = awkward1.layout.NumpyArray(jagged.content[6:])
result = awkward1.layout.fromroot_nestedvector(byteoffsets, rawdata, 2, numpy.dtype(">f").itemsize, ">f")
q = numpy.asarray(result.content.content).astype("<f")
num += len(result.content.content)
walltime = time.time() - starttime
print("TTree NEW jagged2\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
file = ROOT.TFile("data/sample-jagged2.root")
tree = file.Get("jagged2")
starttime = time.time()
for i in range(5):
result = root_numpy.tree2array(tree, "branch", start=branch.basket_entrystart(i), stop=branch.basket_entrystop(i))
walltime = time.time() - starttime
print("TTree root_numpy jagged2\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged3.root")["jagged3"]["branch"]
for i in range(5):
jagged = branch.basket(i, asgenobj(STLVector(STLVector(STLVector(asdtype(">f4")))), branch._context, 6))
q = awkward.fromiter(jagged)
num += len(q.content.content.content)
walltime = time.time() - starttime
print("TTree OLD jagged3\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged3.root")["jagged3"]["branch"]
for i in range(5):
jagged = branch.basket(i, uproot.asdebug)
byteoffsets = awkward1.layout.Index64(jagged.offsets)
rawdata = awkward1.layout.NumpyArray(jagged.content[6:])
result = awkward1.layout.fromroot_nestedvector(byteoffsets, rawdata, 3, numpy.dtype(">f").itemsize, ">f")
q = numpy.asarray(result.content.content.content).astype("<f")
num += len(result.content.content.content)
walltime = time.time() - starttime
print("TTree NEW jagged3\t", walltime, "sec;\t", num/walltime/1e6, "million floats/sec")
|