]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Debug.scl
(refs #7606) Timing with task name (Debug module)
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Debug.scl
1 import "Prelude"
2 import "JavaBuiltin" as Java
3
4 importJava "java.lang.System" where
5     nanoTime :: () -> <Proc> Long
6
7 """
8 Executes the expression and returns the result
9 together with execution time in seconds.
10 """
11 time :: (<e> a) -> <Proc,e> (a,Double)
12 time f = do
13     beginTime = nanoTime ()
14     result = f
15     endTime = nanoTime ()
16     (result, Java.l2d (endTime-beginTime) * 1e-9)
17
18 reportTime :: (<e> a) -> <e> a
19 reportTime f = runProc do
20     beginTime = nanoTime ()
21     result = f
22     endTime = nanoTime ()
23     time = Java.l2d (endTime-beginTime) * 1e-9
24     print "time \(time) s"
25     result
26     
27 reportTimeM :: String -> (<e> a) -> <e> a
28 reportTimeM task f = runProc do
29     beginTime = nanoTime ()
30     result = f
31     endTime = nanoTime ()
32     time = Java.l2d (endTime-beginTime) * 1e-9
33     print "\(task): \(time) s"
34     result    
35
36 """
37 Prints the given text and returns
38 the second parameter.
39 """
40 trace :: String -> a -> a
41 trace text value = runProc do
42     printString text
43     value
44
45 """
46 Prints the given value and returns
47 the second parameter.
48 """
49 traceShow :: Show a => a -> b -> b
50 traceShow p v = trace (show p) v
51