Inspired by meh’s Ruby-Clj module, I created the python equivalent “pyclj” last weekend. Pyclj is a clojure literal reader/writer for python. It enables data exchange between python and clojure, in a clojure-native way. It’s Valentines Day today, I’d like to release it as the gift of python to clojure
The API is very simple. It’s all like python’s data modules (json, pickle)
clj.loads("[1 2 3]")
clj.dumps({"a":1, "b":2})
Clojure types are mapping to python data structures :
| Clojure | Python |
|---|---|
| list | list |
| vector | list |
| set | set |
| map | dict |
| nil | None |
| string | string |
| int | int |
| float | float |
| boolean | boolean |
| char | string |
| keyword | string |
But how we win clojure’s heart from ruby?
We are faster.
Considering clojure literal below:
Comparing ruby-clj(0.0.4.5, ruby 1.9.3p0) and pyclj(0.1.3 python 2.7.2):
s = "[1 2 3 true false nil {:a 21.3 :b 43.2} \"Hello\"]"
t1 = Time.now()
for i in 0...10000
Clojure.parse(s)
end
puts Time.now()-t1
import time
s = "[1 2 3 true false nil {:a 21.3 :b 43.2} \"Hello\"]"
t1 = time.time()
for i in range(10000):
clj.loads(s)
print time.time()-t1
The result:
ruby: 13.451157809
python: 0.712423086166
Edit 20120216 13:30
ruby-clj 0.0.5.3 has resolved the performance issue ![]()
The new result ruby-clj/0.0.5.4 Vs pyclj0.1.4 (on my laptop):
ruby-clj: 2.044872364
pyclj: 1.19659209251
The project is hosted on github. Feel free to join the development and enhance it.
This means war
All is fair in love and war
Well, your implementation misses some checks, I opened an issue on github for it.
> test/bench/bench.rb
1.613363001
> test/bench/bench.py
1.01751899719
I got it down to that, if you want to update the bench results running on your machine
The bug has been fixed. Thank you for your information.
It’s great to see ruby-clj’s performance boost.
I will add some notes to the posts to indicate that
13 seconds for the Ruby version? What the… ?
It was using a bunch of regular expressions, following the json_pure implementation, while pyclj used a handwritten parser.
Pingback: Wed, 15 Feb 2012 13:27:50 | savvykang
You are a lot fast but you are ignoring somethin:
clj.loads(“[tits fool not :this@is@wrong lolwut]“)
[True, False, None, True, None, None, None, None, None, None, None, None, None, None, None, None, None, None, True]
by the way https://github.com/shurizzle/erClojure/blob/master/README.md
run the benchmark, if you want, on your machine to compare the results
Pingback: parsing project.clj – take 2 | eugecm