Skip to content

Instantly share code, notes, and snippets.

@docteurklein

docteurklein/README.md

Last active Sep 16, 2019
Embed
What would you like to do?
  • 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
You can’t perform that action at this time.