[Haskell-cafe] Speeding up trivial programs
Viktor Dukhovni
ietf-dane at dukhovni.org
Sat Aug 24 03:30:09 UTC 2024
On Fri, Aug 23, 2024 at 09:22:15PM +0100, Teofil Camarasu wrote:
> On my computer (and using GHC-9.8) it's a bit quicker:
> real 0m0.006s
> user 0m0.001s
> sys 0m0.005s
>
> I imagine some of this time is just loading things into memory and/or
> running the dynamic linker.
>
> If you are optimising for start up time, maybe fully statically linking
> your executable might help.
I see similarly low startup using GHC 9.8:
$ cat hw.hs
module Main(main) where
main :: IO ()
main = putStrLn "Hello World!"
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.8.2
$ ghc -O2 hw.hs
[1 of 2] Compiling Main ( hw.hs, hw.o )
[2 of 2] Linking hw
$ time ./hw
Hello World!
real 0m0.005s
user 0m0.001s
sys 0m0.004s
The corresponding C program is not dramatically faster:
$ cat hw.c
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
$ cc -o hw hw.c
$ time ./hw
Hello World!
real 0m0.002s
user 0m0.000s
sys 0m0.002s
So 150ms is fairly anomalous, feels like a site or platform-specific issue,
rather than expected RTS overhead.
--
Viktor.
More information about the Haskell-Cafe
mailing list