]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Debug.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Debug.scl
diff --git a/bundles/org.simantics.scl.runtime/scl/Debug.scl b/bundles/org.simantics.scl.runtime/scl/Debug.scl
new file mode 100644 (file)
index 0000000..9411201
--- /dev/null
@@ -0,0 +1,33 @@
+import "Prelude"
+import "JavaBuiltin" as Java
+
+importJava "java.lang.System" where
+    nanoTime :: () -> <Proc> Long
+
+"""
+Executes the expression and returns the result
+together with execution time in seconds.
+"""
+time :: (<e> a) -> <Proc,e> (a,Double)
+time f = do
+    beginTime = nanoTime ()
+    result = f
+    endTime = nanoTime ()
+    (result, Java.l2d (endTime-beginTime) * 1e-9)
+
+"""
+Prints the given text and returns
+the second parameter.
+"""
+trace :: String -> a -> a
+trace text value = runProc do
+    printString text
+    value
+
+"""
+Prints the given value and returns
+the second parameter.
+"""
+traceShow :: Show a => a -> b -> b
+traceShow p v = trace (show p) v
+