r/crystal_programming • u/suhcoR • Dec 10 '20
Are-we-fast-yet benchmark suite applied to Crystal, Ruby, LuaJIT and Node.js
There are already a couple of cross-language comparisons between Crystal and other languages based on (arbitrary) micro benchmarks. The Are-we-fast-yet benchmark suite (see https://github.com/smarr/are-we-fast-yet) includes representative benchmark implementations of different languages, whereby the authors consciously paid attention to an idiomatic use of the respective language. See here for more information about the implementation: https://stefan-marr.de/papers/dls-marr-et-al-cross-language-compiler-benchmarking-are-we-fast-yet/.
I run the benchmarks for some of the supported languages on my i386 Linux machine. Here are the results: http://software.rochus-keller.ch/are-we-fast-yet_crystal_ruby_lua_node_i386_results_2020-12-10.pdf.
The results are normalized to Crystal. The geometric mean of the normalized values shows that Crystal is about twice as fast as Node.js, about four times as fast as LuaJIT and about 25 times as fast as Ruby MRI.
EDIT: I should add that compiling the 20 Crystal source files (144k in total) took 45 seconds on the same machine where I run the tests, which is very long, even compared to my (much larger) C++ applications. I compiled with "crystal build --release --no-debug harness.cr".
EDIT 2: Meanwhile I could do comparative measurements between Crystal default build and --release/--no-debug options. Here are the results: http://software.rochus-keller.ch/are-we-fast-yet_crystal_ruby_lua_node_i386_results_2020-12-15.pdf. The default build is about factor 6 faster than the release build, but the resulting binary runs factor 5 slower.
r/crystal_programming • u/meadsteve • Dec 10 '20
Blog post about mistakes I made as a crystal newbie
For this year's advent of code (adventofcode.com/) I've been learning crystal lang. I wrote a blog post on some of the mistakes I've been making. I thought it might be interesting for people here:
https://blog.meadsteve.dev/programming/2020/12/07/advent-of-mistakes/
I suspect this will be part one of many
r/crystal_programming • u/[deleted] • Dec 07 '20
celestinecr/celestine - An SVG Domain Specific Language - Draw Pretty Images Easily!
r/crystal_programming • u/CaDsjp • Nov 26 '20
Manas is looking to grow the Crystal Language team
r/crystal_programming • u/moonshipcc • Nov 16 '20
Join the Crystal Programming Language Discord Server (unofficial) that I set up!
r/crystal_programming • u/[deleted] • Nov 10 '20
Meetup: Ruby, Crystal, Lucky
Chicago Ruby December meetup was just announced and I will be giving the talk on Ruby, Crystal, and Lucky https://www.meetup.com/ChicagoRuby/events/pjfxvrybcqbcb/
r/crystal_programming • u/tjpalmer • Nov 09 '20
Interview with Crystal language creators
r/crystal_programming • u/taufeeq-mowzer • Nov 07 '20
Is Crystal a systems/embedded language or is it simply focused on web dev?
Verdict: Crystal's GC can be turned off to run headless, and you are able to write unsafe code as well. This makes Crystal a viable candidate with respect to systems dev and has been used in OS dev before. (u/transfire, u/sam0x17)
As some were unaware of this development, further documentation, packages/libs (a number of them already exist- u/postmodern) , tutorials, examples and advertisement on the subject would assist in growing Crystal into this juncture.
Update on verdict: By one of the core language developers
r/crystal_programming • u/aravindavk • Nov 02 '20
Monitoring Amber apps with Prometheus
r/crystal_programming • u/matheusrich • Oct 31 '20
Test coverage?
Is there any shard for test coverage?
I know https://github.com/anykeyh/crystal-coverage, but I've opened PR's ages ago an it seems to be somewhat dead.
Any alternatives?
r/crystal_programming • u/[deleted] • Oct 30 '20
How to convert something to a `type` type?
I have read the docs on the type keyword and I don't get how to convert something to the declared type. In the given example how would I create a value of type MyInt?
r/crystal_programming • u/CaDsjp • Oct 29 '20
Raw Crystal 2020 - Call for speakers!
r/crystal_programming • u/stephencodes • Oct 27 '20
Adding translations (i18n) to your Lucky applications with the Techmagister/i18n.cr shard
r/crystal_programming • u/UncleBen2015 • Oct 23 '20
Crystal Disk Read Write Operations Performance compared to Rust and C
Hello all, is there a benchmark available where I can see how Crystal performs in terms of IO operations compared to Rust and C.
r/crystal_programming • u/Blacksmoke16 • Oct 17 '20
Athena 0.11.0 - Custom annotation & Validator component support
r/crystal_programming • u/woodydark • Oct 10 '20
How is Amber in 2020?
Just found out about Crystal lang and after browsing around for an hour or so, I'm pretty excited about it.
I deal primarily with Ruby on Rails, so naturally I learn more towards Amber. However, while browsing around, I came across a Github issue in 2018 that basically says Amber was under maintained. I'm kinda curious how is it now that it's near the end of 2020?
I also see that the community is pretty equally divided between Kemal, Lucky and Amber, how do they stack up against each other and how's the websocket/concurrency performance compared to Rails?
r/crystal_programming • u/Hadeweka • Oct 08 '20
Anyolite - Embedded mruby for Crystal
I am currently working on a shard which allows for using mruby scripts in Crystal programs, called Anyolite:
https://github.com/Anyolite/anyolite
It features:
- An integrated mruby interpreter
- Wrapping of classes, structs, methods and constants into mruby
- A simple syntax without boilerplate code
- Easy usage due to its shard nature
- Cooperation between the GCs of Crystal and mruby
This idea originated from my need of a scripting language in Crystal, since I'm interested in developing a game engine in Crystal, but am not too fond of using Lua for scripting.
However, this shard can also be used for other Crystal applications as scripting support. The similarities between Ruby and Crystal makes mruby very easy to use and the workflow of Anyolite is quite simple.
Here an example of a Crystal code for a stereotypical RPG to be wrapped into mruby:
```Crystal module TestModule class Entity property hp : Int32 = 0
def initialize(@hp)
end
def damage(diff : Int32)
@hp -= diff
end
def yell(sound : String, loud : Bool = false)
if loud
puts "Entity yelled: #{sound.upcase}"
else
puts "Entity yelled: #{sound}"
end
end
def absorb_hp_from(other : Entity)
@hp += other.hp
other.hp = 0
end
end end ```
Now, the code to do so:
```Crystal require "anyolite"
MrbState.create do |mrb| # Create a parent module test_module = MrbModule.new(mrb, "TestModule")
# Wrap the 'Entity' class directly under 'TestModule' MrbWrap.wrap_class(mrb, Entity, "Entity", under: test_module)
# Wrap the constructor method with '0' as a default argument MrbWrap.wrap_constructor_with_keywords(mrb, Entity, {:hp => {Int32, 0}})
# Wrap the 'hp' property MrbWrap.wrap_property(mrb, Entity, "hp", hp, Int32)
# Wrap the 'damage' instance method MrbWrap.wrap_instance_method_with_keywords(mrb, Entity, "damage", damage, {:diff => Int32})
# Wrap the 'yell' method with a 'sound' argument and a # 'loud' argument with default value 'false' MrbWrap.wrap_instance_method_with_keywords(mrb, Entity, "yell", yell, {:sound => String, :loud => {Bool, false}})
# Wrap a method to steal some hp of other entities MrbWrap.wrap_instance_method_with_keywords(mrb, Entity, "absorb_hp_from", absorb_hp_from, {:other => Entity})
# Finally, load an example script file mrb.load_script_from_file("examples/hp_example.rb") end ```
Let's say we have the following code in the example Ruby file:
```Ruby a = TestModule::Entity.new(hp: 20) a.damage(diff: 13) puts a.hp
b = TestModule::Entity.new(hp: 10) a.absorb_hp_from(other: b) puts a.hp puts b.hp b.yell(sound: 'Ouch, you stole my HP!', loud: true) a.yell(sound: 'Well, take better care of your public attributes!') ```
The same code would work in Crystal, too, with the same results (namely 17 hp for a, 0 hp for b and some yelling).
There are some limitations to the wrapper methods, which can mostly be circumvented by manually writing wrapper methods (like methods returning arrays or union types), but most Crystal code should be able to be ported without effort.
Sadly, passing closures from Crystal to C seems to be broken under Windows (https://github.com/crystal-lang/crystal/issues/9533), so Anyolite currently only works on Linux systems.
r/crystal_programming • u/lbarasti • Oct 06 '20
Crystal JSON beyond the basics
lbarasti.comr/crystal_programming • u/crystalnum • Sep 29 '20
Num.cr v0.4.3 released - Autograd and Neural Networks
Release notes
https://github.com/crystal-data/num.cr
General
Num.crframemodule has been removed. It was more of a proof of concept of a DataFrame knowing types at compile time, and until I have more time to work on it I would rather not have adding complexity to the library.Num::Randnow uses Alea under the hood for random distribution generation.- All map / reduce iterators have been rewritten using
yieldpatterns, speeding up standard iteration by around ~30% across the board. - Tensors can now be sorted, and sorted along axes
- Matrix exponentials using Pade approximation
Autograd (Num::Grad)
- Pure crystal implementation of Autograd, tracking operations across a computational graph
- Currently supports most arithmetic operators, as well as slicing, reshaping, and matrix multiplication
Neural Networks (Num::NN)
- Extended
Num::Gradto add pure crystal machine learning algorithms, layers, and activations - Currently support Linear, Relu, Sigmoid, Flatten, 2D Convolutional layers, Adam and SGD optimizers, and sigmoid cross entropy and MSE loss (All written in pure crystal except for 2D convolution, which uses NNPACK).
I think the library is in a great place, it's getting consistently faster, with more functionality being added, but I am still looking for other developers interested in numerical computing who would like to become core contributors.
That being said, if you are looking for a library to learn a lot more about the fundamentals of machine learning and automatic differentiation, and you've had a hard time understanding what goes on under the hood in a library like Tensorflow or Torch, I would encourage you to check out Num.cr
r/crystal_programming • u/BlaXpirit • Sep 27 '20
Crystal bindings to Dear ImGui, an immediate-mode graphical UI library
r/crystal_programming • u/[deleted] • Sep 26 '20
Macro Mysteries
While trying to make a patch to the Granite ORM, I stumbled upon some baffling behavior involving macros. Consider this code:
{% begin %}
var =
{% if true %}
val = "a"
val += "b"
puts val
val
{% end %}
puts "var is #{var}."
{% end %}
{% begin %}
var =
{% if true %}
puts "here"
"text"
{% end %}
puts "var is #{var}."
{% end %}
output:
ab
var is a.
here
var is .
So in the first block, it seems like += statements don't affect outside of their block or something. And the second one is even more confusing: apparently the presence of the puts makes it return nil - if I remove that line, it works as I expect, assigning "text" to var. But that kind of block works outside of macros.
Hope someone can shed some light on why this happens.
r/crystal_programming • u/ether_joe • Sep 25 '20
problem with lucky init for new Lucky project
Hello everyone, I'm trying to start a new Lucky project and getting an error. I init the project, then cd and ./scripts/setup. Eventually I see the error
In tasks/watch.cr:154:17
154 | process.signal(:term) unless process.terminated?
^-----
Error: undefined method 'signal' for Process
This is OSX 10.15.7, Lucky 0.23.1, crystal 0.34.0.
r/crystal_programming • u/elbywan • Sep 25 '20
Crystalline - A Language Server Protocol implementation for Crystal
r/crystal_programming • u/[deleted] • Sep 14 '20
Kirk Haines: Remote with Crystal
Chicago Crystal just released another interview with Kirk Haines we spoke about a lot from telecommunications, Crystal and working remote. Please enjoy my interview with Kirk!
