doing m a th. “Cryst a l is a gener a l-purpose, object- oriented l a ngu a ge. With synt a x inspired by Ruby, it’s a compiled l a ngu a ge with st a tic type-checking. Types a re resolved by a n a dv a nced type inference a lgorithm” https://cryst a l-l a ng.org/#intro 3
st execution • Bin a ry distribution • Low memory consumption • More errors c a ptured before execution • E a sy tr a nsition from Ruby • Synt a x • Fl a vour/Feeling • Very good a t de a ling with bin a ry d a t a a nd n a tive libr a ries 4
• St a tic • No runtime Met a progr a mming, inste a d compile-time Met a progr a mming • The type system is more powerful • Enums • Struct • Generics • Union Types • Nill a ble Types • Other types • Some di ff erences in liter a ls a nd control f low 8 ^ According to me ^^ According to R a ilC a r’s a uthor, S a m Ruby
Benchmark 1: ruby fib.rb Tim e ( m ean ± σ): 359.1 m s ± 8.1 m s [User: 351.7 m s, Syste m : 5.6 m s] Range ( mi n … m ax): 350.1 m s … 376.9 m s 10 runs Ruby 4.0.2 - 18.5 MB 13
18.93 MB hyperfine - w 3 'ruby --yjit fib.rb' Benchmark 1: ruby --yjit fib.rb T im e ( m ean ± σ): 92.9 m s ± 0.7 m s [User: 87.2 m s, Syste m : 4.7 m s] Range ( mi n … m ax): 92.0 m s … 95.1 m s 31 runs 0ms 200ms 400ms Ruby 4.0.2 Ruby --yjit 4.0.2 92.9 359.1 14
- 276.53 MB hyperfine - w 3 'crystal fib.rb' Benchmark 1: crystal fib.rb T im e ( m ean ± σ): 566.3 m s ± 7.6 m s [User: 483.8 m s, Syste m : 222.1 m s] Range ( mi n … m ax): 550.0 m s … 574.6 m s 10 runs 0ms 300ms 600ms Ruby 4.0.2 Ruby --yjit 4.0.2 Cryst a l 566.3 92.9 359.1 15
1.19 (compiled) - 2.48 MB crystal build --release -o fib-cr-release fib.rb hyperfine - w 3 './fib-cr-release' Benchmark 1: ./fib-cr-release T im e ( m ean ± σ): 21.5 m s ± 1.1 m s [User: 20.6 m s, Syste m : 0.5 m s] Range ( mi n … m ax): 19.0 m s … 23.9 m s 138 runs 0ms 300ms 600ms Ruby Ruby YJIT C ryst a l C om piled 21.5 566.3 92.9 359.1 16
- 4.09 MB go build -o fib-go fib.go hyperfine - w 3 './fib-go' Benchmark 1: ./fib-go T im e ( m ean ± σ): 21.2 m s ± 0.8 m s [User: 20.4 m s, Syste m : 0.7 m s] Range ( mi n … m ax): 19.8 m s … 23.6 m s 132 runs 0ms 300ms 600ms Ruby Ruby YJIT C ryst a l C om piled G o 21.2 21.5 566.3 92.9 359.1 17
Language 0s 20s 40s 60s 80s Ruby Ruby YJIT C ryst a l com p G o 6 3.23 24.21 71.56 18 Ruby https://github.com/M a rioAri a sC/pep a / Cryst a l https://github.com/M a rioAri a sC/monyet Go https://github.com/M a rioAri a sC/monkey
nodes at compile-time and produce code that is pasted into a program” https://crystal-lang.org/reference/1.19/syntax_and_semantics/macros/index.html 23