Created
February 23, 2019 08:23
-
-
Save mizunashi-mana/587bab8a719a69aeef6368a39b11bd2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
module Main where | |
import Criterion.Main | |
import Control.DeepSeq | |
import Data.Foldable | |
{- | |
Result: | |
benchmarking standard | |
time 167.5 ms (160.0 ms .. 173.1 ms) | |
0.999 R² (0.997 R² .. 1.000 R²) | |
mean 178.7 ms (173.6 ms .. 186.4 ms) | |
std dev 8.455 ms (5.544 ms .. 11.38 ms) | |
variance introduced by outliers: 12% (moderately inflated) | |
benchmarking strict | |
time 8.392 ms (8.278 ms .. 8.518 ms) | |
0.999 R² (0.998 R² .. 1.000 R²) | |
mean 8.469 ms (8.411 ms .. 8.604 ms) | |
std dev 241.4 μs (109.9 μs .. 390.4 μs) | |
variance introduced by outliers: 11% (moderately inflated) | |
-- | |
GHC 8.6.3 | |
Option -O2 | |
OS macOS 10.14.3 (Mojave) | |
CPU 2.2GHz Core i7 | |
Memory 8GB DDR3 | |
-} | |
main :: IO () | |
main = do | |
let n = 2 ^ (20 :: Int) | |
let !l = force $ replicate n 1 :: [Int] | |
defaultMain | |
[ bench "standard" $ nf (foldl (+) 0) l | |
, bench "strict" $ nf (foldl' (+) 0) l | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
これだと
foldl
がインライン展開されないのでに変えたら性能差はなくなりました。