I want to print a list of integrals separated with spaces to stdout. The list generation is fast, so I tried to solve this problem with the sequence [1..200000].
In C, I can implement it like this:
#include "stdio.h"
int main()
{
int i;
for(i = 0; i <= 200000; ++i)
printf("%d ", i);
return 0;
}
The fastest solution in Haskell I could implement is about three times slower:
import Data.List (intercalate)
main = putStr . intercalate " " . map (show) $ [1..(200000)]
I tried ByteStrings in some ways, but with them it got even slower. The big problems seems to be the conversion of the integers to strings with show (or the conversion to ByteStrings).
Any suggestions how to speed this up without interfacing to C? It should not become to complicated (as short and beautiful as possible, using other Haskell modules is fine).