-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance of Scan? #141
Comments
@Boarders: The thing that the |
@Gabriel439 : Thanks for the reply (this is also a very nice library btw!)! I did try running the examples from the documentation (i.e. the various sumAndLength functions) using an input list
With implementations: sumAndLength :: Num a => [a] -> (a, Int)
sumAndLength xs = (sum xs, length xs)
sumAndLength' :: Num a => [a] -> (a, Int)
sumAndLength' xs = foldl' step (0, 0) xs
where
step (x, y) n = (x + n, y + 1)
data Pair a b = Pair !a !b
sumAndLength_Pair :: Num a => [a] -> (a, Int)
sumAndLength_Pair xs = done (foldl' step (Pair 0 0) xs)
where
step (Pair x y) n = Pair (x + n) (y + 1)
done (Pair x y) = (x, y)
sumAndLength_foldl = L.fold ((,) <$> L.sum <*> L.length) Is this the correct measure for the library and if so are these numbers to be expected? I would be happy to make a pull request with these benchmarks added if they are relevant to the library. EDIT: I got the numbers wrong but the point remains largely identical. |
@Boarders: Yeah, that is the correct measurement. I think most of the difference in performance is due to I'd also welcome adding the benchmarks to the library |
Running this on the list
This makes it seem like the |
The benchmark that I wrote for this is here. When I get some free time I will add something similar to the library. It does look though like there is a space leak in the code. |
Your first example uses |
Recently I was benchmarking various versions of what essentially amounts to:
I wondered how the foldl does at this task and so ran benchmarking on the input
[0..10^6]
. I tried the following implementation:Criterion gives the following output:
Is performance like this on an example like this to be expected?
I should note that what I really want is to have:
I don't know how to do this in one pass with the
foldl
library but doing it naively in haskell (as thefoldl
documentation suggests one shouldn't do):gives extremely good performance on the same benchmark:
The text was updated successfully, but these errors were encountered: