[GHC] #13070: time after evaluation

GHC ghc-devs at haskell.org
Mon Jan 9 12:44:53 UTC 2017


#13070: time after evaluation
-------------------------------------+-------------------------------------
        Reporter:  vanto             |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.0.2
       Component:  GHCi              |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by vanto):

 * status:  closed => new
 * resolution:  invalid =>


Comment:

 Thank you.[[BR]]
 Though your code in the answer is not adapted I agree with you.
 However the timing varies.  Timing (and memory) is given roughly. If it is
 for educational purpose then why not,  otherwise the result is
 wrong.[[BR]][[BR]]

 You know that time never varies in a computation into a CPU. It is
 impossible!

 Here is a function:[[BR]]

 {{{
 fact :: Integer -> Integer
 fact n = if n==0 then 1 else n*fact(n-1)
 }}}

 {{{
 let x = fact 123456
 }}}
 In GHCi, the time to compute 10 times x is:[[BR]]

 {{{
 1)  55.10 secs,    21,427,209,296 bytes
 2)  5.07 secs,    230,369,932 bytes
 3)  5.05 secs,    230,369,932 bytes
 4)  4.98 secs,    230,372,432 bytes
 5)  4.59 secs,    230,367,100 bytes
 6)  5.57 secs,    230,372,576 bytes
 7)  5.58 secs,    230,368,404 bytes
 8)  5.19 secs,    230,367,872 bytes
 9)  5.37 secs,    230,372,576 bytes
 10) 5.32 secs,    230,368,404 bytes
 }}}
 However  as you can see, timing is not correct to return x.
 And is 55.10 secs a correct time? I say no. See evidence below.
 If I compute 10 times "fact 123456" I have:[[BR]]

 {{{
 1)   50.79 secs,    21,427,207,192 bytes
 2)   49.66 secs,    21,427,207,840 bytes
 3)   50.08 secs,    21,427,208,388 bytes
 4)   49.23 secs,    21,427,206,484 bytes
 5)   49.12 secs,    21,427,207,840 bytes
 6)   48.58 secs,    21,427,207,788 bytes
 7)   47.55 secs,    21,427,209,036 bytes
 8)   47.66 secs,    21,427,206,536 bytes
 9)   48.16 secs,    21,427,206,484 bytes
 10)  46.88 secs,   21,427,208,984 bytes
 }}}
 Which is the real time?
 And if I compute 10 times "fact 12345" I have:[[BR]]

 {{{
 1)   0.80 secs,   172,989,980 bytes
 2)   1.06 secs,   172,985,364 bytes
 3)   0.89 secs,   172,986,620 bytes
 4)   0.83 secs,   172,985,364 bytes
 5)   0.86 secs,   172,984,624 bytes
 6)   0.78 secs,   172,988,552 bytes
 7)   0.81 secs,   172,986,924 bytes
 8)   0.87 secs,   172,987,520 bytes
 9)   1.08 secs,   172,985,728 bytes
 10) 1.12 secs,   172,985,364 bytes
 }}}
 The timing varies. This is not correct. And as you can see, the amount of
 memory is not the same.

 In a Central Processing Unit (CPU) the activities are cyclical. The
 processor fetches an instruction, performs the operations required,
 fetches the next instruction, and so on.[[BR]]
 This orderly sequence of events requires a free running oscillator clock
 which furnishes the reference for all processor actions.[[BR]]
 The combined fetch and execution of a single instruction is referred to as
 an Instruction Cycle. The portion of a cycle identified with a clearly
 defined activity is called a State. And the interval between pulses of the
 timing oscillator is referred to as a Clock Period.[[BR]]
 As a general rule, one or more clock periods are necessary for the
 completion of a state, and there are several states in a cycle.

 For example, with Intel 8080A CPU, the instruction set "MOVr1,r2" which is
 "Move register to register" has 5 Clock Cycles, and the instruction set
 "INR M" which is "Increment memory" has 10 Clock Cycles.[[BR]][[BR]]

 Time never varies.[[BR]][[BR]]

 I think that the code which implements {{{:set +s}}} is to be rewritten if
 the values of time (and memory) are used for work otherwise it is
 acceptable, but it would be better to indicate it in the help of GHCi that
 the time is approximate and the memory also.[[BR]]
 What do you think?

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


More information about the ghc-tickets mailing list