Article: Increasing the D Compiler Speed by Over 75%
JS
js.mdnq at gmail.com
Mon Jul 29 03:15:30 PDT 2013
On Thursday, 25 July 2013 at 21:27:47 UTC, Walter Bright wrote:
> On 7/25/2013 11:49 AM, Dmitry S wrote:
>> I am also confused by the numbers. What I see at the end of
>> the article is
>> "21.56 seconds, and the latest development version does it in
>> 12.19", which is
>> really a 43% improvement. (Which is really great too.)
>
> 21.56/12.19 is 1.77, i.e. a >75% improvement in speed.
>
> A reduction in time would be the reciprocal of that.
Actually, it is a 43% speed improvement. 0.43*21.56 = 9.27s
So if it is 43% faster, it means it's reduced the time by 9.27s
or, 21.56 - 9.27 = 12.28 seconds total.
Now, if we started at 12.28 seconds and it jumped to 21.56 then
it would be 21.56/12.19 = 1.77 ==> 77% longer.
21.56/12.19 != 12.19/21.56.
The order matters.
To make it obvious. Suppose the running time is 20 seconds. You
optimize it, it is 100% **faster**(= 1.0*20 = 20s seconds), then
it takes 0 seconds(20 - 20).
Suppose the running time is 20 seconds, you screw it up, it takes
40 seconds, now it is 100% slower(1.0*20 = 20, and 20 + 20 = 40).
In both cases there is a difference of 20 seconds BUT they mean
very different things.
A 20% increase is not calculated the same as a 20% decrease.
That is,
(A - B)/A != (A - B)/B.
The LHS is relative to A and the RHS is relative to B.
So
(21.56 - 12.19)/21.56 = 9.37/21.56 = 43%
or
1 - 12.19/21.56 = 1 - 0.57 = 0.43
To make the numbers simple,
20 second original, 10 second new.
How much faster is the new version? it is 10 seconds faster, or
in percent, 1 - 10/20 = 0.5% (BUT if we started with 10 seconds
then it would be increase of 100%)
The numbers are very close to the original, but not very close to
75%.
Basically you are calculating the percentage as if you slowed
down the program... but it is not the same.
Another example will suffice:
Suppose you have 1000$. You lose 10% of it, or 100$. You now have
900$. You gain 10% of it, or 90$. You now have 990$! (Where did
the 10$ go?)
This is why the stock market and economy is much worse than 2007
even though the numbers look the same. Easier: Suppose you have
1000$ loose 99% then gain 99%, you have only (1000*0.01)*1.99 =
10*1.99 = 19.9... no where near your original amount. (Even
though the DIJA isn't a percentage this issue does creep into the
calculation due to inflation and other factors)
More information about the Digitalmars-d-announce
mailing list