Skip to content

Commit

Permalink
Add Python polyglot
Browse files Browse the repository at this point in the history
  • Loading branch information
zaknuces committed May 26, 2019
1 parent 8e8c458 commit 6e0cbf6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ruby/json/truffle-node-polyglot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ docker build -t json-truffle-node .
docker run -it json-truffle-node

## Run cpusampler
ruby --polyglot --experimental-options --single-threaded --cpusampler --cpusampler.Mode=statements test-profile.rb
ruby --polyglot --experimental-options --single-threaded --cpusampler --cpusampler.Mode=statements test-profile.rb

## Run Python example
ruby --jvm --polyglot test-time-py.rb
4 changes: 2 additions & 2 deletions ruby/json/truffle-node-polyglot/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
echo 'Run IPS test'
ruby --jvm --polyglot --experimental-options --single-threaded test-ips.rb
#echo 'Run IPS test'
#ruby --jvm --polyglot --experimental-options --single-threaded test-ips.rb
echo 'Run time benchmark'
ruby --jvm --polyglot --experimental-options --single-threaded test-time.rb
# To run ruby polyglot in native mode. Image rebuild is needed.
Expand Down
16 changes: 16 additions & 0 deletions ruby/json/truffle-node-polyglot/test-time-py.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'benchmark'

Benchmark.bm do |x|
x.report {
jobj = Polyglot.eval('python', 'import json; \
text = open(\'./1.json\', \'r\').read(); \
json.loads(text);')
coordinates = Polyglot.as_enumerable(jobj[:coordinates])
x = y = z = 0
coordinates.each do |coord|
x += coord['x']
y += coord['y']
z += coord['z']
end
}
end
2 changes: 1 addition & 1 deletion ruby/json/truffle/test-time.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'benchmark'
require 'json'

enchmark.bm do |x|
Benchmark.bm do |x|
x.report {
jobj = JSON.parse(File.read('1.json'))
coordinates = jobj['coordinates']
Expand Down

0 comments on commit 6e0cbf6

Please sign in to comment.