Initial benchmark: comparing haskell's Text with icu on EN corpus

Run `make all` to run the benchmark.
This commit is contained in:
Félix Baylac-Jacqué 2021-06-29 21:02:27 +02:00
commit f4815eb60c
4 changed files with 65 additions and 0 deletions

22
Makefile Normal file
View File

@ -0,0 +1,22 @@
CFLAGS=-O2 -Wall $(shell pkgconf -cflags icu-io)
LDFLAGS=$(shell pkgconf -libs icu-io)
CC=gcc
all: haskell-read-utf8 icu-read-utf8 bench
.PHONY: all
bench: haskell-read-utf8 icu-read-utf8
hyperfine ./haskell-read-utf8 ./icu-read-utf8
.PHONE: bench
haskell-read-utf8: ./haskell/HaskellReadUTF8.hs
ghc -o ./haskell-read-utf8 -O ./haskell/HaskellReadUTF8.hs
icu-read-utf8: ./icu/icu-read-utf8.c
$(CC) $(CFLAGS) $(LDFLAGS) ./icu/icu-read-utf8.c -o ./icu-read-utf8
clean:
rm -f ./haskell/*.{o,hi}
rm -f ./haskell-read-utf8
rm -f ./icu-read-utf8
.PHONY: clean

24
default.nix Normal file
View File

@ -0,0 +1,24 @@
{ pkgs ? import <nixpkgs> {} }:
let ghcClosure =
pkgs.haskellPackages.ghcWithPackages
(p:[
p.text
]);
in pkgs.stdenv.mkDerivation {
pname = "bench-my-utf8";
version = "0.0.1";
installPhase = ''
mkdir -p $out/bin
mv haskell-read-utf8 $out/bin
'';
nativeBuildInputs = [
pkgs.gnumake
ghcClosure
pkgs.gcc
pkgs.icu
pkgs.hyperfine
pkgs.pkgconf
];
}

View File

@ -0,0 +1,7 @@
module Main where
import qualified Data.Text.IO as TIO
import qualified Data.Text as T
main :: IO ()
main = TIO.readFile "text-test-data/english.txt" >> pure ()

12
icu/icu-read-utf8.c Normal file
View File

@ -0,0 +1,12 @@
#include <unicode/ustdio.h>
#include <stdlib.h>
#include <unicode/umachine.h>
int main(void)
{
UFILE *in = u_fopen("text-test-data/english.txt", "r", NULL, "UTF-8");
UChar *charBuff = malloc(100000000 * sizeof(UChar));
int32_t i = u_file_read(charBuff, 100000000, in);
u_printf("%s\n", charBuff);
u_printf("%i\n", i);
}