Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 43 lines (34 sloc) 1.391 kb
567e041 Frederic Ye [enhance] profiler: moved profiler into core
Aqua-Ye authored
1 /*
2 Copyright © 2011, 2012 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 CoreProfiler = {{
20
21 /** [measure(n)(f)] returns a pair: f() and the float representing the number of
22 seconds needed to execute f, n times. The timing information should have
23 better than millisecond precision, hence making it suitable for execution
24 profiling. */
25 measure(n)(f)=
26 get_time = %%BslTime.get_accurate_time%% : -> float
27 t_beg = get_time()
28 rec aux(n, v) =
29 if n == 0 then
30 t_end = get_time()
31 (t_end - t_beg, v)
32 else
33 aux(n-1, f())
34 aux(n-1, f())
35
36 /** [instrument(n,report)(f)] returns the value of f() and call report with the time needed to execute f, n times */
37 instrument(n, report)(f)=
38 (t, r) = measure(n)(f)
39 do report(t) : void
40 r
41
42 }}
Something went wrong with that request. Please try again.