minhajuddin

minhajuddin

https://github.com/minhajuddin/benchmark-large-json-parsing

Benchmark large json parsing

A few crude benchmarks for Elixir, Golang and Ruby

Processor Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
OS: Ubuntu 16.04

10mb.json

Golang [jq]

$ time jq '.' data/10mb.json > /dev/null
real    0m0.567s
user    0m0.551s
sys     0m0.016s

Elixir

Time taken [Poison]: 1218.831ms
Time taken [Jason]: 508.461ms

Ruby

time ruby app.rb

real    0m0.220s
user    0m0.203s
sys     0m0.017s

100mb.json (sf-city-lots-json/citylots.json at master · zemirco/sf-city-lots-json · GitHub)

Golang [jq]

$ time jq '.' data/citylots.json > /dev/null

real    0m14.436s
user    0m13.992s
sys     0m0.420s

Elixir

  Time taken [Poison]: 32_640.87ms
  Time taken [Jason]: 11_602.128ms

Ruby

  $ time ruby app.rb

  real    0m4.738s
  user    0m4.498s
  sys     0m0.240s

Showing Posts 1 to 10

amnu3387

amnu3387

Does this mean Ruby San, is the fastests fasters ?

(btw shouldn’t this be done with benchee or so?)

brightball

brightball

Seems about right. Would be nice to have Jiffy in there as well just for comparison sake.

One important thing to consider when looking at those numbers: the Go and Elixir solutions are written in pure Go and pure Elixir respectively.

I don’t know what they’re using on the Ruby side but most efficient code in Ruby/Python/PHP/Perl is just directly calling C.

michalmuskala

michalmuskala

The Ruby parser is implemented in C, so it’s more like comparing C to Elixir. Obviously C is going to be faster :wink: We’re not doing that bad actually. It would be interesting to compare with Jason compiled with HiPE. In my benchmarks this makes it at least twice as fast.

The data is also quite different from what you’d face in a regular HTTP app - the JSON is pretty-printed, most JSON flying on the wire is not. This can have significant difference in the actual performance. Depending on what you want to learn from this, it can be important.

Shikada

Shikada

There’s exactly 0 chance that Ruby is not just calling some C lib for this :smiley:
Still, for native Elixir this is reassuringly fast.

brightball

brightball

Don’t suppose you’d be up for tweaking the Techempower benchmarks for Elixir to use Jason with HiPE. It’s the basis for the results of so much of those tests I think it would go a long way with the report.

OvermindDL1

OvermindDL1

Let’s have some fun, here is how they compare to C++/rapidjson:

# Golang
$ time jq '.' data/10mb.json > /dev/null

real    0m0.607s
user    0m0.603s
sys     0m0.004s

$ time jq '.' data/citylots.json > /dev/null

real    0m14.348s
user    0m13.839s
sys     0m0.504s
# Elixir
## 10mb.json
Time taken [Jason]: 521.655ms
Time taken [Poison]: 1358.531ms
## citylots.json
Time taken [Jason]: 12224.44ms
Time taken [Poison]: 33350.239ms
# Ruby
## 10mb.json
$ time ruby app.rb

real    0m0.350s
user    0m0.250s
sys     0m0.020s
## citylots.json
$ time ruby app.rb

real    0m5.632s
user    0m5.393s
sys     0m0.236s
# C++
$ time ./rapidjson-testing < ../../benchmark-large-json-parsing/data/10mb.json 

real    0m0.035s
user    0m0.034s
sys     0m0.000s

$ time ./rapidjson-testing < ../../benchmark-large-json-parsing/data/citylots.json 

real    0m0.531s
user    0m0.503s
sys     0m0.028s

Admittedly this benchmark is flawed because jq is outputting to stdout and elixir/ruby/C++ are just kind of blackholing the data after it is parsed, so jq/go is artificially limited here. In addition the elixir version is actually instancing a tree to hold the whole structure, which is wasted work as well (unsure about ruby). The C++ version is fully parsing and performing callbacks for every parse (standard sax parsing).

I can PR the C++ one in it if you want, it only needs the normal C++ compiler and cmake installed, nothing else needed (not even rapidjson, it acquires it itself). :slight_smile:

OvermindDL1

OvermindDL1

Just to make sure, here is the C++ version as both a sax parser, and as an elixir-style-structure-building document parser (yay eating memory):

$ time ./rapidjson-sax < ../../benchmark-large-json-parsing/data/10mb.json 

real    0m0.038s
user    0m0.034s
sys     0m0.004s

$ time ./rapidjson-sax < ../../benchmark-large-json-parsing/data/citylots.json 

real    0m0.529s
user    0m0.485s
sys     0m0.044s
$ time ./rapidjson-structure < ../../benchmark-large-json-parsing/data/10mb.json 

real    0m0.037s
user    0m0.036s
sys     0m0.000s

$ time ./rapidjson-structure < ../../benchmark-large-json-parsing/data/citylots.json 

real    0m0.533s
user    0m0.504s
sys     0m0.028s

Not much of a difference, honestly the C++ compiler is so good that it is probably being optimized out, hmm…

EDIT: And I added some code to print out some details about the structure to ensure it is compiled and parsed in full and it somehow got a few milliseconds faster… so yeah those are accurate, C++ is just fast as always…

minhajuddin

minhajuddin OP

Would love a PR :smiley:

minhajuddin

minhajuddin OP

You are right about jq doing more work, I’ll use the standard json parser and make it match the ruby and elixir versions.

Not sure you mean by this:

In addition the elixir version is actually instancing a tree to hold the whole structure, which is wasted work as well (unsure about ruby).

Elixir would parse the data and have it in memory.

The C++ version seems insane, I’d love to add a Rust benchmark too. I know this is all crude benchmarking but it gives you a sense of comparison.

minhajuddin

minhajuddin OP

I didn’t use Benchee because the run times are fairly large. I’ll see if I can add benchee with small json loads.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
nseaSeb
AcmeScript — Writing JS hooks as if I were still using Elixir I’ve been having fun building a little something over the last few days: Ac...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews