Created
March 8, 2012 05:35
-
-
Save tanakh/1998936 to your computer and use it in GitHub Desktop.
文字列連結ベンチ ref: http://qiita.com/items/3066
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 OverloadedStrings #-} | |
import Data.Monoid | |
import Blaze.ByteString.Builder as B | |
import Blaze.ByteString.Builder.Char.Utf8 as BT | |
import qualified Data.ByteString.Char8 as BS | |
import qualified Data.Text as T | |
import qualified Data.Text.Encoding as T | |
import Criterion.Main | |
concatBT :: [T.Text] -> T.Text | |
concatBT = T.decodeUtf8 . B.toByteString . mconcat . map BT.fromText | |
concatBB :: [BS.ByteString] -> BS.ByteString | |
concatBB = B.toByteString . mconcat . map B.fromByteString | |
main :: IO () | |
main = defaultMain | |
[ bench "String" $ nf concat $ replicate 1000 ("hello" :: String) | |
, bench "blaze (Text)" $ whnf concatBT $ replicate 1000 ("hello" :: T.Text) | |
, bench "blaze (BS)" $ whnf concatBB $ replicate 1000 ("hello" :: BS.ByteString) | |
] |
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
warming up | |
estimating clock resolution... | |
mean is 1.427688 us (640001 iterations) | |
found 6395 outliers among 639999 samples (1.0%) | |
6056 (0.9%) high severe | |
estimating cost of a clock call... | |
mean is 37.01206 ns (12 iterations) | |
found 1 outliers among 12 samples (8.3%) | |
1 (8.3%) high mild | |
benchmarking String | |
mean: 71.54872 us, lb 71.11242 us, ub 72.54105 us, ci 0.950 | |
std dev: 3.221645 us, lb 1.745424 us, ub 6.485196 us, ci 0.950 | |
found 5 outliers among 100 samples (5.0%) | |
3 (3.0%) high mild | |
2 (2.0%) high severe | |
variance introduced by outliers: 42.508% | |
variance is moderately inflated by outliers | |
benchmarking blaze (Text) | |
mean: 93.39355 us, lb 92.54418 us, ub 94.62662 us, ci 0.950 | |
std dev: 5.182060 us, lb 3.906787 us, ub 7.223113 us, ci 0.950 | |
found 7 outliers among 100 samples (7.0%) | |
4 (4.0%) high mild | |
3 (3.0%) high severe | |
variance introduced by outliers: 53.465% | |
variance is severely inflated by outliers | |
benchmarking blaze (BS) | |
mean: 25.15464 us, lb 24.74210 us, ub 26.21941 us, ci 0.950 | |
std dev: 3.155812 us, lb 1.518559 us, ub 6.576698 us, ci 0.950 | |
found 12 outliers among 100 samples (12.0%) | |
3 (3.0%) high mild | |
9 (9.0%) high severe | |
variance introduced by outliers: 86.249% | |
variance is severely inflated by outliers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment