
On Wed, 2009-09-02 at 11:55 +0800, Steve wrote:
On Tue, 2009-09-01 at 08:45 +0400, Eugene Kirpichov wrote:
Hm, on my machine Don's code has exactly the same performance my code above. That's strange.
Also, replacing the 'test' and 'parse' functions with this one
add :: Int -> Int -> S.ByteString -> Int add k i s = fst $ S.foldl' f (i, 0) s where f (!i, !n) '\n' | n`divisibleBy`k = (i+1, 0) | otherwise = (i, 0) f (!i, !n) w = (i, 10*n+ord w-ord '0')
increases performance by another 15% (0.675s vs 0.790s)
On my system I get a 50% slowdown using this add function!
I guess is just shows that benchmarking code on one single CPU/memory/OS/ghc combination does not give results that apply widely. I'm using: AMD Athlon X2 4800 2GB memory Linux (Fedora 11, 64-bit version) ghc 6.10.3
I should have also said that the test method and test data is important too. This is what I have been using: $ time ./0450 < 0450.input.data and looking at the 'real' value. The file 0450.input.data is generated with a Python script: #!/usr/bin/env python ''' generate a data file for problem 0450 ''' from __future__ import division # new in 2.2, redundant in 3.0 from __future__ import absolute_import # new in 2.5, redundant in 2.7/3.0 from __future__ import print_function # new in 2.6, redundant in 3.0 import io import random inFile = '0450.input.data' #n, k, tiMax = 10**6, 3, 10**9 n, k, tiMax = 10**7, 3, 10**9 with io.open(inFile, 'wb') as f: f.write('%d %d\n' % (n, k)) for i in xrange(n): ti = random.randint(1, tiMax) f.write('%d\n' % (ti,)) Steve