Permalink
Browse files

Added Debug.logTime

  • Loading branch information...
albertdahlin committed Jul 16, 2018
1 parent b06aa44 commit 7408414ac806cefd42315cee76b12f8ca53cd37b
Showing with 31 additions and 2 deletions.
  1. +20 −1 src/Debug.elm
  2. +11 −1 src/Native/Debug.js
View
@@ -1,13 +1,14 @@
module Debug exposing
( log
, crash
, logTime
)
{-| This library is for investigating bugs or performance problems. It should
*not* be used in production code.
# Debugging
@docs log, crash
@docs log, crash, logTime
-}
import Native.Debug
@@ -60,3 +61,21 @@ crash : String -> a
crash =
Native.Debug.crash
{-| Benchmark evaluation time of a function.
This will "wrap" `fn` in a timer and log the eval time in the console.
logTime "name in console" fn arg
If a function uses multiple args, just put parentheses around all but the last arg.
logTime "render header" (render arg1 arg2) arg3
On Chrome, this will also be printed in the profiler timeline.
-}
logTime : String -> (a -> b) -> a -> b
logTime =
Native.Debug.logTime
View
@@ -22,9 +22,19 @@ function crash(message)
throw new Error(message);
}
function logTime(name, fn, arg)
{
console.time(name);
var returnValue = fn(arg);
console.timeEnd(name);
return returnValue;
}
return {
crash: crash,
log: F2(log)
logTime: F3(logTime),
};
}();
}();

0 comments on commit 7408414

Please sign in to comment.