First of all, what is Crystal! However, to put it simply, it is a programming language designed to run programs at execution speed similar to C language using ruby syntax. This time, I wrote an article with the hope of briefly introducing the appeal of this crystal.
First of all, if you do not have crystal installed, please install it from official site according to your environment. After that, create a crystal folder in a suitable place. Next, create test.cr in the crystal folder and edit the contents as follows.
puts "Hello World!"
As you can see, it is a program that displays characters. If you execute this like ruby, the execution speed will be as follows.
time crystal test.cr
→ Hello world!
→ crystal test.cr 0.85s user 0.27s system 134% cpu 0.833 total
This time, if you compile test.cr (convert all the contents of the file to a state that can be read by the personal computer at once) and then execute it, the result will be as follows.
crystal build test.cr --release
time ./test
→ Hello world!
→ ./test 0.00s user 0.00s system 2% cpu 0.263 total
By comparison, it can be seen that the former was 0.85 seconds, while the latter was 0.00 seconds, which is at least 10 times faster.
The above is also described in this site. If you want to know more, I think you should see this as well.
Recommended Posts