Skip to content

Instantly share code, notes, and snippets.

@docteurklein
Last active September 16, 2019 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docteurklein/bf3174494c96431e4bf6329d5479f2bb to your computer and use it in GitHub Desktop.
Save docteurklein/bf3174494c96431e4bf6329d5479f2bb to your computer and use it in GitHub Desktop.
  • why is it that the haskell Text.CSV version is always around twice as slow?
  • how can I use ; as a column separator in the haskell Text.CSV version?
import Data.Char
import Data.Csv
import qualified Data.ByteString.Lazy.Char8 as BL
main = do
BL.putStrLn $ encodeWith defaultEncodeOptions {
encDelimiter = fromIntegral (ord ';')
} $ [
("id", "group")] ++ [
(("id-" ++ show x ++ show y), "group-" ++ show x)
| x <- [1..90], y <- [1..222]]
import Text.CSV
main = do
putStrLn $ printCSV [[
"col1",
"col2"]]
putStrLn $ printCSV [[
"id-" ++ show x ++ show y,
"group-" ++ show x] | x <- [1..90], y <- [1..222]]
-- ghc -dynamic csv.hs
-- time ./csv
-- ./csv 0.10s user 0.06s system 99% cpu 0.156 total
<?php declare(strict_types=1);
$fd = fopen('php://output', 'a');
fputcsv($fd, [
'col1',
'col2',
], ';');
for($i=1; $i <= 90; $i++) {
for($j=1; $j <= 222; $j++) {
fputcsv($fd, [
"id-$i$j",
"group-$i",
], ';');
}
}
// time php csv.php
// php csv.php 0.02s user 0.07s system 99% cpu 0.090 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment