Skip to content

Instantly share code, notes, and snippets.

@straight-shoota
Created July 2, 2022 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save straight-shoota/01856c5c20e0d6b4f87e6f25029a9b71 to your computer and use it in GitHub Desktop.
Save straight-shoota/01856c5c20e0d6b4f87e6f25029a9b71 to your computer and use it in GitHub Desktop.
Crystal comparison Windows vs Linux (with `samples/havlak.cr`)

Comparing compile time and run time performance of Crystal on Windows and Linux. The sample program is https://github.com/crystal-lang/crystal/blob/b7f3f102fd68fcf9fe4f074513c9e374ec98b492/samples/havlak.cr

Both binaries are built and executed on the same system via WSL (this might cause a little bias, but WSL2 performance is very comparative between Windows and Linux). Hardware is a XPS 9710 with i7 11800H.

;TLDR: Compiler performance is very similar, except for LLVM codegen where Windows has the edge (this is probably due to the newer LLVM version). Runtime performance

$ crystal --version
crystaCrystal 1.4.1 [b7377c041] (2022-04-22)

LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu
$ crystal.exe --version
Crystal 1.4.1 [b7377c041] (2022-04-22)

LLVM: 13.0.0
Default target: x86_64-pc-windows-msvc
$ crystal build --release --stats samples/havlak.cr
Parse:                             00:00:00.002025088 (   1.02MB)
Semantic (top level):              00:00:00.180437926 (  59.05MB)
Semantic (new):                    00:00:00.006361227 (  59.05MB)
Semantic (type declarations):      00:00:00.018391310 (  59.05MB)
Semantic (abstract def check):     00:00:00.005011947 (  59.05MB)
Semantic (ivars initializers):     00:00:00.020375194 (  75.05MB)
Semantic (cvars initializers):     00:00:00.127692737 (  91.05MB)
Semantic (main):                   00:00:00.084724068 ( 107.05MB)
Semantic (cleanup):                00:00:00.000183628 ( 107.05MB)
Semantic (recursive struct check): 00:00:00.007681606 ( 107.05MB)
Codegen (crystal):                 00:00:00.409984520 ( 107.11MB)
Codegen (bc+obj):                  00:00:11.679792029 ( 107.11MB)
Codegen (linking):                 00:00:00.105900791 ( 107.11MB)

Codegen (bc+obj):
 - no previous .o files were reused
$ crystal.exe build --release --stats samples/havlak.cr
Parse:                             00:00:00.002484800 (   0.75MB)
Semantic (top level):              00:00:00.760553500 (  59.50MB)
Semantic (new):                    00:00:00.002639600 (  59.50MB)
Semantic (type declarations):      00:00:00.059864200 (  59.50MB)
Semantic (abstract def check):     00:00:00.020422400 (  59.50MB)
Semantic (ivars initializers):     00:00:00.016176700 (  59.50MB)
Semantic (cvars initializers):     00:00:00.151736900 (  75.50MB)
Semantic (main):                   00:00:00.120951400 (  91.50MB)
Semantic (cleanup):                00:00:00.000239900 (  91.50MB)
Semantic (recursive struct check): 00:00:00.002510900 (  91.50MB)
Codegen (crystal):                 00:00:00.210046300 (  91.50MB)
Codegen (bc+obj):                  00:00:04.653456400 (  91.50MB)
Codegen (linking):                 00:00:00.865642400 (  91.50MB)

Codegen (bc+obj):
 - no previous .o files were reused
 $ time ./havlak
Welcome to LoopTesterApp, Crystal edition
Constructing Simple CFG...
15000 dummy loops
Constructing CFG...
Performing Loop Recognition
1 Iteration
Another 50 iterations...
..................................................
Found 76002 loops (including artificial root node) (3800100)
./havlak  11,84s user 0,71s system 173% cpu 7,222 total
$ powershell.exe -c 'Measure-Command { .\havlak.exe | Out-Default }'
Welcome to LoopTesterApp, Crystal edition
Constructing Simple CFG...
15000 dummy loops
Constructing CFG...
Performing Loop Recognition
1 Iteration
Another 50 iterations...
..................................................
Found 76002 loops (including artificial root node) (3800100)


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 8
Milliseconds      : 92
Ticks             : 80929671
TotalDays         : 9,36686006944444E-05
TotalHours        : 0,00224804641666667
TotalMinutes      : 0,134882785
TotalSeconds      : 8,0929671
TotalMilliseconds : 8092,9671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment