#1523: Constant overhead of threadDelay
----------------------------+-----------------------------------------------
Reporter: chak | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 6.8.3
Component: libraries/base | Version: 6.7
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: x86
Os: MacOS X |
----------------------------+-----------------------------------------------
Changes (by thorkilnaur):
* owner: thorkilnaur =>
Comment:
For this test, I compare these versions of GHC:
{{{
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.6.20070220
$ /Users/thorkilnaur/tn/GHCDarcsRepository/ghc-HEAD-complete-for-pulling-
and-copying-20070713_1212/ghc/compiler/stage2/ghc-inplace --version
The Glorious Glasgow Haskell Compilation System, version 6.9.20080219
$
}}}
Initially, I have ktrace'd runs of a program (the testsuite's
concio001.hs) containing a single threadDelay call using the two GHC
versions and observed that the number of select calls dropped from 82 to
5. So the cure has certainly worked towards reducing the number of select
calls.
To measure the threadDelay overhead, I use:
{{{
$ cat threadDelayTest1.hs
import System
import Control.Concurrent
totalDelay = 1000000
main = do
argv <- getArgs
let
stepDelay = read $ argv!!0
stepCount = totalDelay`div`stepDelay
in do
putStrLn $ "Performing " ++ show stepCount ++ " delays of " ++ show
stepDelay ++ " microsecs"
sequence_ $ replicate stepCount $ threadDelay stepDelay
putStrLn "Done"
$
}}}
With the old GHC version, I get:
{{{
$ ghc --make threadDelayTest1.hs
[1 of 1] Compiling Main ( threadDelayTest1.hs,
threadDelayTest1.o )
Linking threadDelayTest1 ...
$ time ./threadDelayTest1 1000000
Performing 1 delays of 1000000 microsecs
Done
real 0m1.609s
user 0m0.010s
sys 0m0.042s
$ time ./threadDelayTest1 1000000
Performing 1 delays of 1000000 microsecs
Done
real 0m1.156s
user 0m0.007s
sys 0m0.022s
$ time ./threadDelayTest1 100000
Performing 10 delays of 100000 microsecs
Done
real 0m2.057s
user 0m0.112s
sys 0m0.339s
$ time ./threadDelayTest1 10000
Performing 100 delays of 10000 microsecs
Done
real 0m15.069s
user 0m1.222s
sys 0m3.672s
$ time ./threadDelayTest1 1000
Performing 1000 delays of 1000 microsecs
Done
real 2m30.095s
user 0m12.390s
sys 0m37.142s
$
}}}
From these measurements, the overhead can be computed as 0.1, 0.14, and
0.15 seconds for each threadDelay for the latter three runs. I also note a
considerable amount of CPU being spent here.
With the recent GHC, I get:
{{{
$ /Users/thorkilnaur/tn/GHCDarcsRepository/ghc-HEAD-complete-for-pulling-
and-copying-20070713_1212/ghc/compiler/stage2/ghc-inplace --make
threadDelayTest1.hs
[1 of 1] Compiling Main ( threadDelayTest1.hs,
threadDelayTest1.o )
Linking threadDelayTest1 ...
$ time ./threadDelayTest1 1000000
Performing 1 delays of 1000000 microsecs
Done
real 0m2.519s
user 0m0.006s
sys 0m0.045s
$ time ./threadDelayTest1 1000000
Performing 1 delays of 1000000 microsecs
Done
real 0m1.123s
user 0m0.005s
sys 0m0.020s
$ time ./threadDelayTest1 100000
Performing 10 delays of 100000 microsecs
Done
real 0m1.314s
user 0m0.005s
sys 0m0.020s
$ time ./threadDelayTest1 10000
Performing 100 delays of 10000 microsecs
Done
real 0m4.131s
user 0m0.007s
sys 0m0.024s
$ time ./threadDelayTest1 1000
Performing 1000 delays of 1000 microsecs
Done
real 0m40.248s
user 0m0.022s
sys 0m0.044s
$
}}}
The overheads are computed as 0.02, 0.03, and 0.04 seconds for the latter
three runs.
I will leave it to others to judge whether this is acceptable.
Best regards Thorkil
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1523#comment:8>
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