jrjackson 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -132,11 +132,11 @@ invokedynamic.class.values=false
132
132
 
133
133
  # # Set the JIT threshold to the specified method invocation count.
134
134
  # # Options: [Integer], Default: 50.
135
- # jit.threshold=50
135
+ jit.threshold=1
136
136
 
137
137
  # # Set the max count of active methods eligible for JIT-compilation.
138
138
  # # Options: [Integer], Default: 4096.
139
- # jit.max=4096
139
+ jit.max=16384
140
140
 
141
141
  # # Set the maximum full-class byte size allowed for jitted methods.
142
142
  # # Options: [Integer], Default: 30000.
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
+ require 'bigdecimal'
4
5
  require 'benchmark'
5
6
  require 'thread'
6
7
  require 'digest'
@@ -62,82 +63,33 @@ end
62
63
 
63
64
  generated_array = []
64
65
  generated_smile = []
65
- q = Queue.new
66
66
 
67
67
  org_array.each do |hsh|
68
68
  generated_array << JrJackson::Raw.generate(hsh)
69
69
  end
70
70
 
71
+ q = Queue.new
72
+
71
73
  Benchmark.bmbm("jackson parse symbol keys: ".size) do |x|
72
74
 
73
75
  x.report("json java parse:") do
74
- th1 = Thread.new(generated_array) do |arry|
75
- 50.times {arry.each {|string| ::JSON.parse("[#{string}]").first }}
76
- q << true
77
- end
78
- th2 = Thread.new(generated_array) do |arry|
79
- 50.times {arry.each {|string| ::JSON.parse("[#{string}]").first }}
80
- q << true
81
- end
82
- q.pop
83
- q.pop
84
- # 50.times {generated_array.each {|string| ::JSON.parse("[#{string}]").first }}
76
+ 50.times {generated_array.each {|string| ::JSON.parse(string) }}
85
77
  end
86
78
 
87
79
  x.report("gson parse:") do
88
- th1 = Thread.new(generated_array) do |arry|
89
- 50.times {arry.each {|string| ::Gson::Decoder.new({}).decode(string) }}
90
- q << true
91
- end
92
- th2 = Thread.new(generated_array) do |arry|
93
- 50.times {arry.each {|string| ::Gson::Decoder.new({}).decode(string) }}
94
- q << true
95
- end
96
- q.pop
97
- q.pop
98
- # 50.times {generated_array.each {|string| ::Gson::Decoder.new({}).decode(string) }}
80
+ 50.times {generated_array.each {|string| ::Gson::Decoder.new({}).decode(string) }}
99
81
  end
100
82
 
101
- x.report("jackson parse raw:") do
102
- th1 = Thread.new(generated_array) do |arry|
103
- 50.times {arry.each {|string| JrJackson::Raw.parse(string) }}
104
- q << true
105
- end
106
- th2 = Thread.new(generated_array) do |arry|
107
- 50.times {arry.each {|string| JrJackson::Raw.parse(string) }}
108
- q << true
109
- end
110
- q.pop
111
- q.pop
112
- # 50.times {generated_array.each {|string| JrJackson::Raw.parse(string) }}
83
+ x.report("jackson parse string keys:") do
84
+ 50.times {generated_array.each {|string| JrJackson::Raw.parse_str(string) }}
113
85
  end
114
86
 
115
87
  x.report("jackson parse symbol keys:") do
116
- th1 = Thread.new(generated_array) do |arry|
117
- 50.times {arry.each {|string| JrJackson::Sym.parse(string) }}
118
- q << true
119
- end
120
- th2 = Thread.new(generated_array) do |arry|
121
- 50.times {arry.each {|string| JrJackson::Sym.parse(string) }}
122
- q << true
123
- end
124
- q.pop
125
- q.pop
126
- # 50.times {generated_array.each {|string| JrJackson::Sym.parse(string) }}
88
+ 50.times {generated_array.each {|string| JrJackson::Raw.parse_sym(string) }}
127
89
  end
128
90
 
129
- x.report("jackson parse string keys:") do
130
- th1 = Thread.new(generated_array) do |arry|
131
- 50.times {arry.each {|string| JrJackson::Str.parse(string) }}
132
- q << true
133
- end
134
- th2 = Thread.new(generated_array) do |arry|
135
- 50.times {arry.each {|string| JrJackson::Str.parse(string) }}
136
- q << true
137
- end
138
- q.pop
139
- q.pop
140
- # 50.times {generated_array.each {|string| JrJackson::Str.parse(string) }}
91
+ x.report("jackson parse raw:") do
92
+ 50.times {generated_array.each {|string| JrJackson::Raw.parse_raw(string) }}
141
93
  end
142
94
 
143
95
  x.report("json java generate:") do
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bigdecimal'
5
+ require 'benchmark'
6
+ require 'thread'
7
+ require 'digest'
8
+ require 'json/ext'
9
+ require 'gson'
10
+
11
+ require File.expand_path('lib/jrjackson')
12
+
13
+ HASH = {:one => nil, :two => nil, :three => nil, :four => {:a => nil, :b => nil, :c =>nil},
14
+ :five => {:d => nil, :e => nil},
15
+ :six => {:f => nil, :g => nil, :h =>nil, :i => nil, :j => nil, :k => nil, :l => nil},
16
+ :seven => nil, :eight => [],
17
+ :nine => {:m => {:A => nil, :B => nil}}}
18
+
19
+ def random_string
20
+ Digest::MD5.hexdigest "#{Time.now + rand(999)}"
21
+ end
22
+
23
+ def random_number
24
+ rand 999_999_999
25
+ end
26
+
27
+ def random_float
28
+ random_number + rand
29
+ end
30
+
31
+ def fill_array
32
+ value = []
33
+ 5.times do
34
+ value.push send(METHODS[rand(3)])
35
+ end
36
+ value
37
+ end
38
+
39
+ def randomize_entries hsh
40
+ new_hsh = {}
41
+ hsh.each_pair do |key, value|
42
+ case value
43
+ when NilClass
44
+ new_hsh[key] = send METHODS[rand(3)]
45
+ when Hash
46
+ new_hsh[key] = randomize_entries value
47
+ when Array
48
+ new_hsh[key] = fill_array
49
+ end
50
+ end
51
+ new_hsh
52
+ end
53
+
54
+ METHODS = [:random_string, :random_number, :random_float]
55
+
56
+ org_array = []
57
+ one = []
58
+
59
+ 0.upto(5000) do |i|
60
+ hsh = HASH.dup
61
+ org_array << randomize_entries(hsh)
62
+ end
63
+
64
+ generated_array = []
65
+ generated_smile = []
66
+
67
+ org_array.each do |hsh|
68
+ generated_array << JrJackson::Raw.generate(hsh)
69
+ end
70
+
71
+ q = Queue.new
72
+
73
+ Benchmark.bmbm("jackson parse symbol keys: ".size) do |x|
74
+
75
+ x.report("json java parse:") do
76
+ th1 = Thread.new(generated_array) do |arry|
77
+ # 50.times {arry.each {|string| ::JSON.parse("[#{string}]").first }}
78
+ 50.times {arry.each {|string| ::JSON.parse(string).first }}
79
+ q << true
80
+ end
81
+ th2 = Thread.new(generated_array) do |arry|
82
+ # 50.times {arry.each {|string| ::JSON.parse("[#{string}]").first }}
83
+ 50.times {arry.each {|string| ::JSON.parse(string).first }}
84
+ q << true
85
+ end
86
+ q.pop
87
+ q.pop
88
+ end
89
+
90
+ x.report("gson parse:") do
91
+ th1 = Thread.new(generated_array) do |arry|
92
+ 50.times {arry.each {|string| ::Gson::Decoder.new.decode(string) }}
93
+ q << true
94
+ end
95
+ th2 = Thread.new(generated_array) do |arry|
96
+ 50.times {arry.each {|string| ::Gson::Decoder.new.decode(string) }}
97
+ q << true
98
+ end
99
+ q.pop
100
+ q.pop
101
+ end
102
+
103
+ x.report("jackson parse raw:") do
104
+ th1 = Thread.new(generated_array) do |arry|
105
+ 50.times {arry.each {|string| JrJackson::Raw.parse_raw(string) }}
106
+ q << true
107
+ end
108
+ th2 = Thread.new(generated_array) do |arry|
109
+ 50.times {arry.each {|string| JrJackson::Raw.parse_raw(string) }}
110
+ q << true
111
+ end
112
+ q.pop
113
+ q.pop
114
+ end
115
+
116
+ x.report("jackson parse symbol keys:") do
117
+ th1 = Thread.new(generated_array) do |arry|
118
+ 50.times {arry.each {|string| JrJackson::Raw.parse_sym(string) }}
119
+ q << true
120
+ end
121
+ th2 = Thread.new(generated_array) do |arry|
122
+ 50.times {arry.each {|string| JrJackson::Raw.parse_sym(string) }}
123
+ q << true
124
+ end
125
+ q.pop
126
+ q.pop
127
+ end
128
+
129
+ x.report("jackson parse string keys:") do
130
+ th1 = Thread.new(generated_array) do |arry|
131
+ 50.times {arry.each {|string| JrJackson::Raw.parse_str(string) }}
132
+ q << true
133
+ end
134
+ th2 = Thread.new(generated_array) do |arry|
135
+ 50.times {arry.each {|string| JrJackson::Raw.parse_str(string) }}
136
+ q << true
137
+ end
138
+ q.pop
139
+ q.pop
140
+ end
141
+
142
+ x.report("json java generate:") do
143
+ 50.times {org_array.each {|hsh| hsh.to_json }}
144
+ end
145
+
146
+ x.report("gson generate:") do
147
+ 50.times {org_array.each {|hsh| ::Gson::Encoder.new({}).encode(hsh) }}
148
+ end
149
+
150
+ x.report("jackson generate:") do
151
+ 50.times {org_array.each {|hsh| JrJackson::Raw.generate(hsh) }}
152
+ end
153
+ end
@@ -0,0 +1,72 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
+ <modelVersion>4.0.0</modelVersion>
4
+ <groupId>com.jrjackson.jruby</groupId>
5
+ <artifactId>jrjackson</artifactId>
6
+ <name>jrjackson</name>
7
+ <version>1.2.2</version>
8
+ <url>http://maven.apache.org</url>
9
+ <build>
10
+ <plugins>
11
+ <plugin>
12
+ <artifactId>maven-compiler-plugin</artifactId>
13
+ <version>3.1</version>
14
+ <configuration>
15
+ <source>1.7</source>
16
+ <target>1.7</target>
17
+ </configuration>
18
+ </plugin>
19
+ <plugin>
20
+ <artifactId>maven-surefire-plugin</artifactId>
21
+ <version>2.16</version>
22
+ <configuration>
23
+ <parallel>methods</parallel>
24
+ <threadCount>10</threadCount>
25
+ </configuration>
26
+ </plugin>
27
+ <plugin>
28
+ <artifactId>maven-shade-plugin</artifactId>
29
+ <version>2.1</version>
30
+ <executions>
31
+ <execution>
32
+ <phase>package</phase>
33
+ <goals>
34
+ <goal>shade</goal>
35
+ </goals>
36
+ <configuration>
37
+ <artifactSet>
38
+ <excludes>
39
+ <exclude>org.jruby:jruby</exclude>
40
+ </excludes>
41
+ </artifactSet>
42
+ </configuration>
43
+ </execution>
44
+ </executions>
45
+ </plugin>
46
+ </plugins>
47
+ </build>
48
+ <dependencies>
49
+ <dependency>
50
+ <groupId>junit</groupId>
51
+ <artifactId>junit</artifactId>
52
+ <version>4.11</version>
53
+ <scope>test</scope>
54
+ <exclusions>
55
+ <exclusion>
56
+ <artifactId>hamcrest-core</artifactId>
57
+ <groupId>org.hamcrest</groupId>
58
+ </exclusion>
59
+ </exclusions>
60
+ </dependency>
61
+ <dependency>
62
+ <groupId>org.jruby</groupId>
63
+ <artifactId>jruby</artifactId>
64
+ <version>1.7.3</version>
65
+ <scope>compile</scope>
66
+ </dependency>
67
+ </dependencies>
68
+ <properties>
69
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
70
+ </properties>
71
+ </project>
72
+
data/jrjackson.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jrjackson'
5
- s.version = '0.1.1'
6
- s.date = '2013-04-03'
5
+ s.version = '0.2.0'
6
+ s.date = '2013-09-30'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Guy Boertje']
9
9
  s.email = ['guyboertje@gmail.com']
@@ -15,14 +15,17 @@ Gem::Specification.new do |s|
15
15
 
16
16
  # = MANIFEST =
17
17
  s.files = %w[
18
+ .jrubyrc
18
19
  Gemfile
19
20
  README.md
20
21
  Rakefile
21
22
  benchmarking/.jrubyrc
22
23
  benchmarking/benchmark.rb
24
+ benchmarking/benchmark_threaded.rb
25
+ dependency-reduced-pom.xml
23
26
  jrjackson.gemspec
24
27
  lib/jrjackson.rb
25
- lib/jrjackson/jars/jrjackson-1.0.jar
28
+ lib/jrjackson/jars/jrjackson-1.2.2.jar
26
29
  lib/jrjackson/jrjackson.rb
27
30
  lib/jrjackson/version.rb
28
31
  lib/require_relative_patch.rb
@@ -30,11 +33,14 @@ Gem::Specification.new do |s|
30
33
  profiling/profiled.rb
31
34
  src/main/java/com/jrjackson/JrJacksonRaw.java
32
35
  src/main/java/com/jrjackson/JrJacksonService.java
33
- src/main/java/com/jrjackson/JrJacksonStr.java
34
- src/main/java/com/jrjackson/JrJacksonSym.java
35
36
  src/main/java/com/jrjackson/ParseError.java
37
+ src/main/java/com/jrjackson/RubyJacksonModule.java
36
38
  src/main/java/com/jrjackson/RubyObjectDeserializer.java
39
+ src/main/java/com/jrjackson/RubyObjectStrDeserializer.java
37
40
  src/main/java/com/jrjackson/RubyObjectSymDeserializer.java
41
+ src/main/java/com/jrjackson/RubyUtils.java
42
+ src/test/java/com/jrjackson/jruby/AppTest.java
43
+ test/jrjackson_test.rb
38
44
  ]
39
45
  # = MANIFEST =
40
46
 
@@ -3,36 +3,42 @@ unless RUBY_PLATFORM =~ /java/
3
3
  exit 255
4
4
  end
5
5
 
6
- require_relative "jars/jrjackson-1.0.jar"
6
+ # require_relative "jars/jrjackson-1.2.1.jar"
7
+ require_relative "jars/jrjackson-1.2.2.jar"
7
8
  require 'com/jrjackson/jr_jackson'
8
9
 
9
10
  module JrJackson
10
11
  module Json
11
12
  class << self
12
13
  TIME_REGEX = %r(\A(\d{4}-\d\d-\d\d|(\w{3}\s){2}\d\d)\s\d\d:\d\d:\d\d)
13
- def load(json_string, options = {})
14
- mod = if options[:raw]
15
- JrJackson::Raw
16
- elsif options[:symbolize_keys]
17
- JrJackson::Sym
18
- else
19
- JrJackson::Str
20
- end
14
+
15
+ def load(json_string, options = nil)
16
+
21
17
  if json_string.is_a?(String) && json_string =~ TIME_REGEX
22
- mod.parse("\"#{json_string}\"")
18
+ return JrJackson::Raw.parse_raw("\"#{json_string}\"")
19
+ end
20
+
21
+ if options && !options.empty?
22
+ if options.size == 1 && !!options[:raw]
23
+ return JrJackson::Raw.parse_raw(json_string)
24
+ end
25
+ if options.size == 1 && !!options[:symbolize_keys]
26
+ return JrJackson::Raw.parse_sym(json_string)
27
+ end
28
+ JrJackson::Raw.parse(json_string, options)
23
29
  else
24
- mod.parse(json_string)
30
+ JrJackson::Raw.parse_str(json_string)
25
31
  end
26
32
  end
27
33
 
28
34
  def dump(object)
29
35
  case object
30
- when Array, Hash
36
+ when Array, Hash, String
31
37
  JrJackson::Raw.generate(object)
32
- when String
33
- "\"#{object}\""
34
- when nil, true, false
35
- object
38
+ when true, false
39
+ object.to_s
40
+ when nil
41
+ 'null'
36
42
  else
37
43
  if object.respond_to?(:to_json)
38
44
  object.to_json
@@ -49,5 +55,3 @@ module JrJackson
49
55
  end
50
56
  end
51
57
  end
52
-
53
- JSON = JrJackson::Json unless defined?(JSON)