Last active
September 3, 2020 18:12
-
-
Save infinity0/77448f5282d5e2ed4ecabdfdb15b205c to your computer and use it in GitHub Desktop.
naive benchmarks, rustc vs ghc
This file contains hidden or 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
$ ghc -O Test.hs && ./Test | |
Sequence.|> [65536 * 5000] took 7.943 ms | |
$ rustc -O test.rs && ./test | |
VecDeque::extend [65536 * 5000] took 619.233631ms |
This file contains hidden or 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
import qualified Data.Sequence as S | |
import qualified Data.ByteString as BS | |
import Control.DeepSeq | |
import Data.Foldable | |
import Data.Traversable | |
import Data.IORef | |
import Data.Word | |
import GHC.Clock | |
import System.IO | |
main :: IO () | |
main = do | |
null <- openFile "/dev/shm/tmphs1234567890" WriteMode | |
d <- newIORef 0 | |
for [1..5000] $ \_ -> do | |
let bs = BS.replicate 65536 0 | |
hPrint null $ bs `deepseq` BS.foldl' (+) 0 bs -- force evaluation | |
let q = S.Empty :: S.Seq Word8 | |
hPrint null $ q -- force evaluation | |
l <- getMonotonicTimeNSec | |
let q2 = BS.foldl' (S.|>) q bs | |
hPrint null $ q2 `deepseq` sum q2 -- force evaluation | |
e <- getMonotonicTimeNSec | |
modifyIORef' d (+ (e - l)) | |
d <- readIORef d | |
putStrLn $ "Sequence.|> [65536 * 5000] took " <> show (fromIntegral d / 1000000.0) <> " ms" |
This file contains hidden or 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
use std::collections::VecDeque; | |
use std::time::{Duration, Instant}; | |
pub fn main() { | |
let mut d = Duration::from_millis(0); | |
for _ in 1..=5000 { | |
let buf = [0; 65536]; | |
let mut queue: VecDeque<u8> = VecDeque::with_capacity(65536); | |
let l = Instant::now(); | |
queue.extend(buf.iter()); | |
d += l.elapsed(); | |
} | |
println!("VecDeque::extend [65536 * 5000] took {:?}", d); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment