Hello Welcome

Reader

Read the latest posts from Hello Welcome.

from Evan Walsh

In my experimentation with Ruby, I wondered what options for various tasks were fastest. This is not a complete measure of quality. Use these numbers wisely.

All of this was done on my early 2013 MacBook Pro (2.7 GHz Intel Core i7 processor, 16 GB 1600 MHz DDR3 RAM).

All the code I used for these benchmarks is available here.

Templating

I wanted to see the speed difference between all these ways of rendering HTML with Ruby.

The competitors:

Engine Iterations per second
Erubi 2701.7
ERB 1460.4
Liquid 1091.2
Markaby 609.5
Slim 345.8
Handlebars 238.0
HAML 234.2

I was surprised how fast Erubi was and how slow HAML is. The gulf between solutions here is quite great. However, don't underestimate developer productivity here.


Markup

I wanted to see how fast different Markdown converters were (especially compared to other markup converters).

The competitors:

Engine Iterations per second
Redcarpet 15475.4
CommonMarker 11321.1
BlueCloth 11233.3
RedCloth 4743.6
Asciidoctor 2377.0
Creole 1947.9
WikiText 1610.2
Maruku 1428.8
Kramdown 940.4

Obviously, gems with a C extension have an edge here. The old standby, Redcarpet, still performs quite well here. Kramdown, my typical choice for static site generators like Jekyll, is slowest but quick enough for most stuff. You probably shouldn't be converting markup that much. Do it once and store the result!


Serialization

I don't actually remember why I was benchmarking all of these, but I did.

The competitors are:

Given a very simple payload of

data = {
  account_id: 1,
  type: 'artist_update',
  subject: {
    id: 1,
    type: 'Artist'
  },
  author: {
    id: 1,
    type: 'Account'
  }
}
Format File size (in bytes)
CBOR 82
MessagePack 82
JSON 109
YAML 110
BSON 123

Ruby to data

Format Iterations per second
CBOR 892477.6
MessagePack 655391.9
BSON 389066.6
JSON 152686.7
YAML 7831.1

Data to Ruby

Format Iterations per second
CBOR 360230.3
BSON 312189.8
MessagePack 177722.6
JSON 152348.3
YAML 5501.0

I've never used CBOR, but now I know it's a good option!

 
Read more...