Skip to content

Instantly share code, notes, and snippets.

@opotowsky
Created April 7, 2015 15:19
Show Gist options
  • Save opotowsky/0ed3a17eedc896965440 to your computer and use it in GitHub Desktop.
Save opotowsky/0ed3a17eedc896965440 to your computer and use it in GitHub Desktop.
line profiling cymetric
$ kernprof -l -v cymetric 60yr.h5 -e "print(Materials[:])"
/home/opotowsky/.local/lib/python2.7/site-packages/cymetric/metrics.py:10: QAWarning: pyne.data is not yet QA compliant.
from pyne import data
SimId QualId ResourceId ObjId \
0 c21bd208-7851-40d0-98ac-c9668490d354 2 11 10
1 c21bd208-7851-40d0-98ac-c9668490d354 2 29 24
2 c21bd208-7851-40d0-98ac-c9668490d354 2 47 38
3 c21bd208-7851-40d0-98ac-c9668490d354 2 65 52
4 c21bd208-7851-40d0-98ac-c9668490d354 2 83 66
5 c21bd208-7851-40d0-98ac-c9668490d354 2 101 80
6 c21bd208-7851-40d0-98ac-c9668490d354 2 119 94
7 c21bd208-7851-40d0-98ac-c9668490d354 2 137 108
8 c21bd208-7851-40d0-98ac-c9668490d354 2 155 122
9 c21bd208-7851-40d0-98ac-c9668490d354 2 173 136
10 c21bd208-7851-40d0-98ac-c9668490d354 2 191 150
11 c21bd208-7851-40d0-98ac-c9668490d354 2 209 164
12 c21bd208-7851-40d0-98ac-c9668490d354 2 627 578
13 c21bd208-7851-40d0-98ac-c9668490d354 2 649 10
14 c21bd208-7851-40d0-98ac-c9668490d354 2 650 596
15 c21bd208-7851-40d0-98ac-c9668490d354 2 652 596
16 c21bd208-7851-40d0-98ac-c9668490d354 2 653 597
17 c21bd208-7851-40d0-98ac-c9668490d354 2 655 596
18 c21bd208-7851-40d0-98ac-c9668490d354 2 656 598
19 c21bd208-7851-40d0-98ac-c9668490d354 2 657 597
20 c21bd208-7851-40d0-98ac-c9668490d354 2 666 10
21 c21bd208-7851-40d0-98ac-c9668490d354 2 667 601
22 c21bd208-7851-40d0-98ac-c9668490d354 2 669 601
23 c21bd208-7851-40d0-98ac-c9668490d354 2 670 602
24 c21bd208-7851-40d0-98ac-c9668490d354 2 672 601
25 c21bd208-7851-40d0-98ac-c9668490d354 2 673 603
26 c21bd208-7851-40d0-98ac-c9668490d354 2 674 602
27 c21bd208-7851-40d0-98ac-c9668490d354 2 683 10
28 c21bd208-7851-40d0-98ac-c9668490d354 2 684 606
29 c21bd208-7851-40d0-98ac-c9668490d354 2 686 606
... ... ... ... ...
4596530 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596531 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596532 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596533 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596534 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596535 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596536 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596537 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596538 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596539 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596540 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596541 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596542 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596543 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596544 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596545 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596546 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596547 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596548 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596549 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596550 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596551 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596552 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596553 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596554 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596555 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596556 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596557 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596558 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
4596559 c21bd208-7851-40d0-98ac-c9668490d354 82483 224680 98733
TimeCreated NucId Mass
0 0 922350000 4.000000e+06
1 1 922350000 4.000000e+06
2 2 922350000 4.000000e+06
3 3 922350000 4.000000e+06
4 4 922350000 4.000000e+06
5 5 922350000 4.000000e+06
6 6 922350000 4.000000e+06
7 7 922350000 4.000000e+06
8 8 922350000 4.000000e+06
9 9 922350000 4.000000e+06
10 10 922350000 4.000000e+06
11 11 922350000 4.000000e+06
12 12 922350000 4.000000e+06
13 12 922350000 3.999995e+06
14 12 922350000 4.971049e+00
15 12 922350000 4.971049e+00
16 12 922350000 0.000000e+00
17 12 922350000 0.000000e+00
18 12 922350000 4.971049e+00
19 12 922350000 4.971049e+00
20 12 922350000 3.999988e+06
21 12 922350000 6.628065e+00
22 12 922350000 6.628065e+00
23 12 922350000 0.000000e+00
24 12 922350000 0.000000e+00
25 12 922350000 6.628065e+00
26 12 922350000 6.628065e+00
27 12 922350000 3.999980e+06
28 12 922350000 8.285082e+00
29 12 922350000 8.285082e+00
... ... ... ...
4596530 719 641600000 1.598404e-05
4596531 719 651590000 2.765635e-05
4596532 719 661600000 6.419397e-07
4596533 719 661610000 7.129064e-06
4596534 719 661620000 3.805395e-06
4596535 719 661630000 4.964062e-07
4596536 719 922340000 1.003109e-04
4596537 719 922350000 2.456461e-03
4596538 719 922360000 1.134647e-04
4596539 719 922370000 1.469159e-07
4596540 719 922380000 1.151130e+00
4596541 719 932370000 2.724153e-04
4596542 719 932390000 2.882453e-04
4596543 719 942370000 3.126231e-07
4596544 719 942380000 1.747898e-02
4596545 719 942390000 3.591930e-01
4596546 719 942400000 1.572227e-01
4596547 719 942410000 1.137926e-01
4596548 719 942420000 6.228094e-02
4596549 719 942430000 1.892752e-06
4596550 719 952410000 9.418936e-03
4596551 719 952420000 4.000404e-06
4596552 719 952430000 1.977015e-02
4596553 719 952440000 3.852138e-06
4596554 719 962420000 1.047678e-03
4596555 719 962430000 1.889004e-05
4596556 719 962440000 9.528774e-03
4596557 719 962450000 4.123295e-04
4596558 719 962460000 3.982264e-06
4596559 719 962470000 1.671794e-08
[4596560 rows x 7 columns]
Wrote profile results to cymetric.lprof
Timer unit: 1e-06 s
Total time: 2087.35 s
File: /home/opotowsky/.local/lib/python2.7/site-packages/cymetric/evaluator.py
Function: eval at line 47
Line # Hits Time Per Hit % Time Line Contents
==============================================================
47 @profile
48 def eval(self, metric, conds=None):
49 """Evalutes a metric with the given conditions."""
50 3 5 1.7 0.0 rawkey = (metric, conds if conds is None else frozenset(conds))
51 3 6 2.0 0.0 if rawkey in self.rawcache:
52 return self.rawcache[rawkey]
53 3 38 12.7 0.0 m = self.get_metric(metric)
54 3 4 1.3 0.0 series = []
55 5 9 1.8 0.0 for dep in m.dependencies:
56 2 18 9.0 0.0 d = self.eval(dep[0], conds=conds)
57 2 13635828 6817914.0 0.7 s = None if d is None else raw_to_series(d, dep[1], dep[2])
58 2 12 6.0 0.0 series.append(s)
59 3 179847195 59949065.0 8.6 raw = m(series=series, conds=conds, known_tables=self.known_tables)
60 3 18 6.0 0.0 if raw is None:
61 return raw
62 3 14 4.7 0.0 self.rawcache[rawkey] = raw
63 # write back to db
64 3 82 27.3 0.0 if (m.name in self.known_tables) or (not self.write):
65 2 2 1.0 0.0 return raw
66 1 2 2.0 0.0 rec = self.recorder
67 1 733 733.0 0.0 rawd = raw.to_dict(outtype='series')
68 4596561 6125292 1.3 0.3 for i in range(len(raw)):
69 4596560 40286557 8.8 1.9 d = rec.new_datum(m.name)
70 36772480 90372553 2.5 4.3 for field, dbtype, shape in m.schema:
71 32175920 49110261 1.5 2.4 fname = m.schema.byte_names[field]
72 32175920 1429381220 44.4 68.5 val = rawd[str(field)][i]
73 32175920 257465482 8.0 12.3 d = d.add_val(fname, val, dbtype=dbtype, shape=shape)
74 4596560 21123106 4.6 1.0 d.record()
75 1 20 20.0 0.0 self.known_tables.add(m.name)
76 1 2 2.0 0.0 return raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment