File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 22
33exports . hrTime = process . hrtime ;
44
5+ exports . gc = function ( ) {
6+ global . gc && global . gc ( ) ;
7+ } ;
8+
59exports . toFixed = function ( n ) {
610 return n . toFixed ( 2 ) ;
711} ;
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ import Prelude hiding (min,max)
2222-- | A wrapper around the Node `process.hrtime()` function.
2323foreign import hrTime :: forall eff . EffFn1 eff (Array Int ) (Array Int )
2424
25+ -- | Force garbage collection.
26+ -- | Requires node to be run with the --force-gc flag.
27+ foreign import gc :: forall eff . Eff eff Unit
28+
2529foreign import toFixed :: Number -> String
2630
2731fromHrTime :: Array Int -> Number
@@ -38,6 +42,9 @@ withUnits t
3842-- | Estimate the running time of a function and print a summary to the console,
3943-- | specifying the number of samples to take. More samples will give a better
4044-- | estimate of both mean and standard deviation, but will increase running time.
45+ -- |
46+ -- | To increase benchmark accuracy by forcing garbage collection before the
47+ -- | benchmark is run, node should be invoked with the '--expose-gc' flag.
4148benchWith
4249 :: forall eff a
4350 . Int
@@ -48,6 +55,7 @@ benchWith n f = runST do
4855 sum2Ref <- newSTRef 0.0
4956 minRef <- newSTRef infinity
5057 maxRef <- newSTRef 0.0
58+ gc
5159 forE 0 n \_ -> do
5260 t1 <- runEffFn1 hrTime [0 , 0 ]
5361 t2 <- const (runEffFn1 hrTime t1) (f unit)
You can’t perform that action at this time.
0 commit comments