in reply to Re^8: Finding the size of a nested hash in a HoH
in thread Finding the size of a nested hash in a HoH
Your benchmark is still fatally flawed.
The major cost of using keys, is the requests for extra memory from the OS in order to build the list of keys. This is a one-off cost, that only occurs the first time the process requests that memory from the OS. By running your code in a loop (using Benchmark), you are amortising that costs over many re-runs, thereby reducing its significance. And by running both methods in the same benchmark, your are further amortising the penalty of that memory allocation over the each method runs which don't need it, thus further skewing the results.
This is a Windows-specific benchmark (due to the use of tasklist.exe in memUsed()) but should be readily adaptable to *nix:
On my system, for 1 million keys, for / keys required 56MB of extra memory and so is 10x slower than while / each:
c:\test>each-keys-b -M1=keys -M2=pairs -N=1e6 hash built, starting timer Took 11.663000 and 56.145MB extra memory for 1000000 using keys/pairs +method c:\test>each-keys-b -M1=each -M2=pairs -N=1e6 hash built, starting timer Took 1.296000 and 0.020MB extra memory for 1000000 using each/pairs me +thod
For 5 million keys, for / keys required 228MB of extra memory and so is 40x slower than while / each:
c:\test>each-keys-b -M1=keys -M2=pairs -N=5e6 hash built, starting timer Took 280.350000 and 228.652MB extra memory for 5000000 using keys/pair +s method c:\test>each-keys-b -M1=each -M2=pairs -N=5e6 hash built, starting timer Took 6.613000 and 0.020MB extra memory for 5000000 using each/pairs me +thod
For 8 million keys, for / keys required 340MB of extra memory and so is 80x slower than while / each:
c:\test>each-keys-b -M1=keys -M2=pairs -N=8e6 hash built, starting timer Took 899.040000 and 343.402MB extra memory for 8000000 using keys/pair +s method c:\test>each-keys-b -M1=each -M2=pairs -N=8e6 hash built, starting timer Took 11.112000 and 0.023MB extra memory for 8000000 using each/pairs m +ethod
And at these sizes of hash, my machine has not yet moved into swapping. When I retire tonight, I'll leave the machine running on 10 million keys which will cause swapping and I'll report the timings tomorrow.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^10: Finding the size of a nested hash in a HoH
by remiah (Hermit) on Nov 12, 2011 at 01:56 UTC | |
by BrowserUk (Patriarch) on Nov 12, 2011 at 02:46 UTC |