#4913: Make event tracing conditional on an RTS flag only
---------------------------------+------------------------------------------
    Reporter:  tibbe             |       Owner:                
        Type:  feature request   |      Status:  new           
    Priority:  normal            |   Component:  Runtime System
     Version:  7.0.1             |    Keywords:                
    Testcase:                    |   Blockedby:                
          Os:  Unknown/Multiple  |    Blocking:                
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown  
---------------------------------+------------------------------------------

Comment(by tibbe):

 I've just benchmarked the current and the proposed approach. The proposed
 approach is about five times faster. Here's the benchmark:

 `trace.c`:
 {{{
 int tracelevel = 0;
 }}}

 `Test.hs`:
 {{{
 {-# LANGUAGE ForeignFunctionInterface #-}

 module Main (main) where

 import Criterion.Main
 import Foreign.C.Types
 import Foreign.Ptr
 import Foreign.Storable
 import GHC.Exts

 foreign import ccall unsafe "&tracelevel" tracelevel :: Ptr CUInt

 traceEventIfEnabled :: String -> IO ()
 traceEventIfEnabled s = do
     enabled <- peek tracelevel
     if enabled > 0
         then traceEvent s
         else return ()

 main = defaultMain
        [ bench "load and branch" (loadAndBranch "")
        , bench "function call" (functionCall "")
        ]

 loadAndBranch :: String -> IO ()
 loadAndBranch s = traceEventIfEnabled s

 functionCall :: String -> IO ()
 functionCall s = traceEvent s
 }}}

 Compile and run:

 {{{
 ghc -O2 -threaded Test.hs trace.c
 ./Test
 }}}

 And the results:

 {{{
 warming up
 estimating clock resolution...
 mean is 8.629898 us (80001 iterations)
 found 1650 outliers among 79999 samples (2.1%)
   1479 (1.8%) high severe
 estimating cost of a clock call...
 mean is 84.59817 ns (63 iterations)
 found 4 outliers among 63 samples (6.3%)
   3 (4.8%) high mild
   1 (1.6%) high severe

 benchmarking load and branch
 collecting 100 samples, 982316 iterations each, in estimated 862.9905 ms
 bootstrapping with 100000 resamples
 mean: 8.819932 ns, lb 8.779123 ns, ub 8.940035 ns, ci 0.950
 std dev: 323.7500 ps, lb 135.2691 ps, ub 692.9337 ps, ci 0.950
 found 9 outliers among 100 samples (9.0%)
   5 (5.0%) high mild
   4 (4.0%) high severe
 variance introduced by outliers: 0.999%
 variance is unaffected by outliers

 benchmarking function call
 collecting 100 samples, 169890 iterations each, in estimated 862.9919 ms
 bootstrapping with 100000 resamples
 mean: 51.03444 ns, lb 50.98904 ns, ub 51.10433 ns, ci 0.950
 std dev: 286.2063 ps, lb 206.6244 ps, ub 408.2373 ps, ci 0.950
 found 9 outliers among 100 samples (9.0%)
   3 (3.0%) high mild
   6 (6.0%) high severe
 variance introduced by outliers: 0.990%
 variance is unaffected by outliers
 }}}

 The current approach takes about 51ns on average while the proposed
 approach takes only 9ns on average.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4913#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to