]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Debug.scl
94112010044ae102b99fa350eb0e168ef6ffcf0d
[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 """
19 Prints the given text and returns
20 the second parameter.
21 """
22 trace :: String -> a -> a
23 trace text value = runProc do
24     printString text
25     value
26
27 """
28 Prints the given value and returns
29 the second parameter.
30 """
31 traceShow :: Show a => a -> b -> b
32 traceShow p v = trace (show p) v
33