Skip to content

Instantly share code, notes, and snippets.

@kgadek
Created March 21, 2013 13:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgadek/5213110 to your computer and use it in GitHub Desktop.
Save kgadek/5213110 to your computer and use it in GitHub Desktop.
Haskell vs Python
## Task: get 20 most common words in given text
## Input: http://home.agh.edu.pl/~dorosz/pjn/lab-01/potop.txt
## take a note this is in ISO-8859-2/CRLF. I converted it to UTF-8/LF:
## $ iconv -f ISO-8859-2 -t UTF-8 potop.txt > potop.tmp
## $ tr -d '\r' < potop.tmp > potop.txt
## Haskell: https://gist.github.com/kgadek/5213089
## uses Parsec
## Python: https://gist.github.com/kgadek/5213092
## uses regexes
➜ zad1 git:(master) ✗ ghc --make -O2 h.hs
➜ zad1 git:(master) ✗ time ./h < potop.txt
[(12597,"i"),(9713,"si\281"),(7650,"w"),(7418,"nie"),(6329,"na"),(5803,"z"),(4287,"to"),(4211,"do"),(3674,"\380e"),(3022,"a"),(1954,"za"),(1873,"pan"),(1859,"bo"),(1741,"po"),(1699,"ale"),(1664,"jak"),(1639,"o"),(1558,"go"),(1545,"co"),(1534,"tak")]
./h < potop.txt 2,68s user 0,08s system 99% cpu 2,769 total
➜ zad1 git:(master) ✗ time ./python.py < potop.txt
12597 --> i
9713 --> się
7650 --> w
7418 --> nie
6329 --> na
5803 --> z
4287 --> to
4211 --> do
3674 --> że
3022 --> a
1954 --> za
1873 --> pan
1859 --> bo
1741 --> po
1699 --> ale
1664 --> jak
1639 --> o
1558 --> go
1545 --> co
1534 --> tak
./python.py < potop.txt 0,68s user 0,01s system 99% cpu 0,698 total
➜ zad1 git:(master) ✗
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment