Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-05 Thread wren ng thornton
Paul Moore wrote: 2009/8/5 Yitzchak Gale : Or is this with an alternate RNG? Although I think even that would be fair, since Python uses Mersenne. I got the impression Dmitry was using Haskell's standard RNG, not Mersenne Twister. If so, then we'd get further improvements with MT, but that's s

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-05 Thread Dmitry Olshansky
> I got the impression Dmitry was using Haskell's standard RNG, not > Mersenne Twister. If so, then we'd get further improvements with MT, > but that's still a hit against Haskell, as I'd interpret it as meaning > that Haskell supplies as default a PRNG which costs noticeable > performance in order

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-05 Thread Paul Moore
2009/8/5 Yitzchak Gale : > Dmitry Olshansky wrote: >> My measurements show that... >> (-O2 gives approx 2 time impovements). >> ...using RandomGen and State monad to generate a list gives at least 4 times >> improvements (on 1 000 000 items). > > You earlier said: > >> this takes over twice as long

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-05 Thread Yitzchak Gale
Dmitry Olshansky wrote: > My measurements show that... > (-O2 gives approx 2 time impovements). > ...using RandomGen and State monad to generate a list gives at least 4 times > improvements (on 1 000 000 items). You earlier said: > this takes over twice as long as a naively implemented Python pro

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-05 Thread Dmitry Olshansky
My measurements show that - using strict version of insertWith doesn't improve performance. - in case of compilation with -O2 flag foldl' also is equal to foldl (-O2 gives approx 2 time impovements).- using RandomGen and State monad to generate a list gives at least 4 times improvements (on 1 000 0

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Daniel Fischer
Am Samstag 01 August 2009 20:50:10 schrieb Sterling Clover: > On Aug 1, 2009, at 2:06 PM, Paul Moore wrote: > > Is the issue with random numbers just the implementation, or is it > > something inherent in the non-pure nature of a random number generator > > that makes it hard for Haskell to impleme

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Anton van Straaten
Sterling Clover wrote: For other random numbers, with different properties (faster, but with tradeoffs in robustness, or ability to split, or both), you can check hackage for at least mersenne-random and gsl-random. gsl-random is definitely worth a try for performance. I recently did a rough

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Sterling Clover
On Aug 1, 2009, at 2:06 PM, Paul Moore wrote: Is the issue with random numbers just the implementation, or is it something inherent in the non-pure nature of a random number generator that makes it hard for Haskell to implement efficiently? If the latter, that probably makes Haskell a somewhat

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Daniel Fischer
Am Samstag 01 August 2009 15:44:39 schrieb Paul Moore: > 2009/7/31 Paul Moore : > > 2009/7/31 Gregory Collins : > > Hmm, I'm obviously still mucking up the performance somehow. My full > program (still a toy, but a step on the way to what I'm aiming at) is > as follows. It's rolling 3 6-sided dice

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Malcolm Wallace
I'm expecting the answer to be that I've got unnecessary laziness - which is fine, but ultimately my interest is in ease of expression and performance combined, so I'm looking for beginner-level improvements rather than subtle advanced techniques like unboxing. You're right, it is too lazy. H

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Paul Moore
2009/8/1 Ketil Malde : > Paul Moore writes: > >> What am I doing wrong here? I'd have expected compiled Haskell to be >> faster than interpreted Python, so obviously my approach is wrong. > > Two things from my experience: Python associative arrays are fast, and > Haskell random numbers are slow.

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Ketil Malde
Paul Moore writes: > What am I doing wrong here? I'd have expected compiled Haskell to be > faster than interpreted Python, so obviously my approach is wrong. Two things from my experience: Python associative arrays are fast, and Haskell random numbers are slow. So by building a map from random

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Pekka Karjalainen
On Sat, Aug 1, 2009 at 4:44 PM, Paul Moore wrote: > PS I know my code is probably fairly clumsy - I'd appreciate style > suggestions, but my main interest here is whether a beginner, with a > broad programming background, a basic understanding of Haskell, and > access to Google, put together a clea

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-01 Thread Paul Moore
2009/7/31 Paul Moore : > 2009/7/31 Gregory Collins : >> Paul Moore writes: >> >>> How would I efficiently write a function in Haskell to count >>> occurrences of unique elements in a (potentially very large) list? For >>> example, given the list [1,2,3,4,5,3,4,2,4] I would like the output >>> [[1,

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-07-31 Thread Deniz Dogan
2009/8/1 Paul Moore : > BTW, I did know that Haskell had an efficient map implementation, I > just wasn't sure how to use it "functionally" - I probably should have > searched a bit harder for examples before posting. Thanks for the help > in any case. Know that Data.Map uses size balanced trees a

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-07-31 Thread Paul Moore
2009/7/31 Gregory Collins : > Paul Moore writes: > >> How would I efficiently write a function in Haskell to count >> occurrences of unique elements in a (potentially very large) list? For >> example, given the list [1,2,3,4,5,3,4,2,4] I would like the output >> [[1,1], [2,2], [3,2], [4,3], [5,1]]

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-07-31 Thread Daniel Fischer
Am Freitag 31 Juli 2009 22:39:53 schrieb Paul Moore: > How would I efficiently write a function in Haskell to count > occurrences of unique elements in a (potentially very large) list? For > example, given the list [1,2,3,4,5,3,4,2,4] I would like the output > [[1,1], [2,2], [3,2], [4,3], [5,1]] (o

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-07-31 Thread Malcolm Wallace
In an imperative language like Python, I'd use a dictionary as an accumulator - something like for el in input: accums[i] = accums.get(i, 0) + 1 Haskell has efficient dictionary structures too, e.g. Data.Map List.foldl' (\m x-> Map.insertWith' (+) x 1 m) Map.empty Regards, Mal

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-07-31 Thread Gregory Collins
Gregory Collins writes: > Paul Moore writes: > >> How would I efficiently write a function in Haskell to count >> occurrences of unique elements in a (potentially very large) list? For >> example, given the list [1,2,3,4,5,3,4,2,4] I would like the output >> [[1,1], [2,2], [3,2], [4,3], [5,1]] (

Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-07-31 Thread Gregory Collins
Paul Moore writes: > How would I efficiently write a function in Haskell to count > occurrences of unique elements in a (potentially very large) list? For > example, given the list [1,2,3,4,5,3,4,2,4] I would like the output > [[1,1], [2,2], [3,2], [4,3], [5,1]] (or some equivalent > representati

[Haskell-cafe] Efficient functional idiom for histogram

2009-07-31 Thread Paul Moore
How would I efficiently write a function in Haskell to count occurrences of unique elements in a (potentially very large) list? For example, given the list [1,2,3,4,5,3,4,2,4] I would like the output [[1,1], [2,2], [3,2], [4,3], [5,1]] (or some equivalent representation). Clearly, this won't be po