minhajuddin

minhajuddin

Crude JSON parsing benchmarks for Elixir, Ruby, Golang

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

Most Liked

michalmuskala

michalmuskala

You’re all making me want to implement Jason.Native again! :sweat_smile:

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.

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:

Where Next?

Popular in Discussions Top

matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39523 209
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
ejpcmac
I have discovered Nix last month and I am currently on my way to migrating to it—both on macOS at home and the full NixOS distrubution at...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
kostonstyle
Hi all How can I compare haskell with elixir, included tools, webservices, ect. Thanks
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54250 245
New

We're in Beta

About us Mission Statement