Thank you for the Haskell version again, which can't help but make me wonder why it would require to go to such lengths to show the compiled timing. Because the most quick and natural thing to do would be just to run it in the interpreter and get the result immediately. Note: we are again comparing apples to oranges.
----- Original Message ---- From: Alexander Schmolck <[EMAIL PROTECTED]> To: General forum <[email protected]> Sent: Friday, July 7, 2006 11:45:31 AM Subject: Re: [Jgeneral] J as a functional programming language Thanks for the nice J version. It looks like I currently lack the time to respond to your other points (or work out what the right hand side after ^: exactly does), so I'll just post a quick timing you requested (and the steps needed to replicate it) for the time being. Possibly more at some other time. Oleg Kobchenko <[EMAIL PROTECTED]> writes: > J504 > ham=: 3 : 'y.{.(2 3 5&([: /:[EMAIL PROTECTED]@, ] , > */))^:((+:y.)"_>:#)^:_] 1' > > > 6!:2 'ham 8000' > 0.234361 > > ham1=: 3 : 'y{.(2 3 5&([: /:[EMAIL PROTECTED]@, ] , */))^:((+:y)>:#)^:_] > 1x' > 6!:2 'ham1 100000' NB. extended > 62.5922 > > How long will it take Haskell? No time at all, since it won't need to do anything. I added the following line main = print (take 1 $ drop hamming 100000) and the compiled and run it with: (ghc hamming.hs -O3 -o hamming; time ./hamming) On my machine the floating point version and infinite precision integer versions take pretty similar amount of time (0.04 for double float and 0.10s for arbitrary precision integers; this contrasts with around 10s for ham and 84s for (the J504 version of) ham1 (there are some variations here, 84s is the fastest I've observed, I've also had 260s). Note: I do only have old versions of J and GHC, and I'm pretty ignorant about GHC and Haskell (this is probably the first time I compiled something with it, usually I rust run small snippets in GHCi) -- so I'm pretty sure one could get (possibly significantly) better performance from both versions. If you really want to know how fast you can get you'll have to ask on the haskell mailing list or on comp.lang.functional (as I've briefly noted, understanding performance issues of haskell code is non-trivial). 'as To obtain the float version, replace e.g. 1 with 1.0 -- ->8- file hamming.hs ->8- hamming = 1 : map (*2) hamming # (map (*3) hamming # map (*5) hamming) where xxs@(x:xs) # yys@(y:ys) | x==y = x : xs#ys | x<=y = x : xs # yys | x>y = y : xxs#ys main = do print $ hamming !! 100000 -- ->8- file hamming.hs ->8- ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
