ffi-yajl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +17 -0
- data/Rakefile +62 -0
- data/bin/ffi-yajl-bench +36 -0
- data/ext/ffi_yajl/ext/encoder/encoder.c +240 -0
- data/ext/ffi_yajl/ext/encoder/extconf.rb +29 -0
- data/ext/ffi_yajl/ext/parser/extconf.rb +29 -0
- data/ext/ffi_yajl/ext/parser/parser.c +199 -0
- data/ext/libyajl2/extconf.rb +65 -0
- data/ext/libyajl2/vendored/.gitignore +3 -0
- data/ext/libyajl2/vendored/BUILDING +23 -0
- data/ext/libyajl2/vendored/BUILDING.win32 +27 -0
- data/ext/libyajl2/vendored/CMakeLists.txt +79 -0
- data/ext/libyajl2/vendored/COPYING +13 -0
- data/ext/libyajl2/vendored/ChangeLog +175 -0
- data/ext/libyajl2/vendored/README +74 -0
- data/ext/libyajl2/vendored/TODO +9 -0
- data/ext/libyajl2/vendored/YAJLDoc.cmake +26 -0
- data/ext/libyajl2/vendored/configure +79 -0
- data/ext/libyajl2/vendored/example/CMakeLists.txt +23 -0
- data/ext/libyajl2/vendored/example/README.md +7 -0
- data/ext/libyajl2/vendored/example/parse_config.c +69 -0
- data/ext/libyajl2/vendored/example/sample.config +101 -0
- data/ext/libyajl2/vendored/perf/CMakeLists.txt +23 -0
- data/ext/libyajl2/vendored/perf/documents.c +1418 -0
- data/ext/libyajl2/vendored/perf/documents.h +28 -0
- data/ext/libyajl2/vendored/perf/perftest.c +134 -0
- data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +39 -0
- data/ext/libyajl2/vendored/reformatter/json_reformat.c +194 -0
- data/ext/libyajl2/vendored/src/CMakeLists.txt +86 -0
- data/ext/libyajl2/vendored/src/YAJL.dxy +1258 -0
- data/ext/libyajl2/vendored/src/api/yajl_common.h +75 -0
- data/ext/libyajl2/vendored/src/api/yajl_gen.h +157 -0
- data/ext/libyajl2/vendored/src/api/yajl_parse.h +226 -0
- data/ext/libyajl2/vendored/src/api/yajl_tree.h +185 -0
- data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +23 -0
- data/ext/libyajl2/vendored/src/yajl +33 -0
- data/ext/libyajl2/vendored/src/yajl.c +175 -0
- data/ext/libyajl2/vendored/src/yajl.pc.cmake +9 -0
- data/ext/libyajl2/vendored/src/yajl_alloc.c +52 -0
- data/ext/libyajl2/vendored/src/yajl_alloc.h +34 -0
- data/ext/libyajl2/vendored/src/yajl_buf.c +103 -0
- data/ext/libyajl2/vendored/src/yajl_buf.h +57 -0
- data/ext/libyajl2/vendored/src/yajl_bytestack.h +69 -0
- data/ext/libyajl2/vendored/src/yajl_encode.c +220 -0
- data/ext/libyajl2/vendored/src/yajl_encode.h +34 -0
- data/ext/libyajl2/vendored/src/yajl_gen.c +354 -0
- data/ext/libyajl2/vendored/src/yajl_lex.c +763 -0
- data/ext/libyajl2/vendored/src/yajl_lex.h +117 -0
- data/ext/libyajl2/vendored/src/yajl_parser.c +498 -0
- data/ext/libyajl2/vendored/src/yajl_parser.h +78 -0
- data/ext/libyajl2/vendored/src/yajl_tree.c +503 -0
- data/ext/libyajl2/vendored/src/yajl_version.c +7 -0
- data/ext/libyajl2/vendored/test/CMakeLists.txt +23 -0
- data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +36 -0
- data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +11 -0
- data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +9 -0
- data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/am_eof.json +1 -0
- data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +4 -0
- data/ext/libyajl2/vendored/test/cases/am_integers.json +1 -0
- data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/am_multiple.json +3 -0
- data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +5 -0
- data/ext/libyajl2/vendored/test/cases/am_stuff.json +7 -0
- data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +14 -0
- data/ext/libyajl2/vendored/test/cases/ap_array_open.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +1 -0
- data/ext/libyajl2/vendored/test/cases/ap_map_open.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +1 -0
- data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +4 -0
- data/ext/libyajl2/vendored/test/cases/array.json +6 -0
- data/ext/libyajl2/vendored/test/cases/array.json.gold +22 -0
- data/ext/libyajl2/vendored/test/cases/array_close.json +1 -0
- data/ext/libyajl2/vendored/test/cases/array_close.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/bignums.json +1 -0
- data/ext/libyajl2/vendored/test/cases/bignums.json.gold +5 -0
- data/ext/libyajl2/vendored/test/cases/bogus_char.json +4 -0
- data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +10 -0
- data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +1 -0
- data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/deep_arrays.json +1 -0
- data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +2049 -0
- data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +1 -0
- data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +36 -0
- data/ext/libyajl2/vendored/test/cases/doubles.json +1 -0
- data/ext/libyajl2/vendored/test/cases/doubles.json.gold +7 -0
- data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +1 -0
- data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +8 -0
- data/ext/libyajl2/vendored/test/cases/empty_array.json +1 -0
- data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/empty_string.json +1 -0
- data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +4 -0
- data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +7 -0
- data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +1 -0
- data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/false.json +1 -0
- data/ext/libyajl2/vendored/test/cases/false.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +1 -0
- data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +1 -0
- data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +1 -0
- data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +1 -0
- data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +2 -0
- data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +5 -0
- data/ext/libyajl2/vendored/test/cases/high_overflow.json +1 -0
- data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/integers.json +3 -0
- data/ext/libyajl2/vendored/test/cases/integers.json.gold +14 -0
- data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +1 -0
- data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +1 -0
- data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +1 -0
- data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +5 -0
- data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +7 -0
- data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +9 -0
- data/ext/libyajl2/vendored/test/cases/lonely_number.json +1 -0
- data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/low_overflow.json +1 -0
- data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/map_close.json +1 -0
- data/ext/libyajl2/vendored/test/cases/map_close.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +1 -0
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +1 -0
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/multiple.json +3 -0
- data/ext/libyajl2/vendored/test/cases/multiple.json.gold +4 -0
- data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +1 -0
- data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +8 -0
- data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +1 -0
- data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +5 -0
- data/ext/libyajl2/vendored/test/cases/null.json +1 -0
- data/ext/libyajl2/vendored/test/cases/null.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +5 -0
- data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +9 -0
- data/ext/libyajl2/vendored/test/cases/simple.json +5 -0
- data/ext/libyajl2/vendored/test/cases/simple.json.gold +9 -0
- data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +11 -0
- data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +5 -0
- data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +1 -0
- data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +3 -0
- data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +1 -0
- data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +3 -0
- data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +7 -0
- data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +2 -0
- data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +1 -0
- data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +7 -0
- data/ext/libyajl2/vendored/test/cases/true.json +1 -0
- data/ext/libyajl2/vendored/test/cases/true.json.gold +2 -0
- data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +1 -0
- data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +4 -0
- data/ext/libyajl2/vendored/test/cases/zerobyte.json +1 -0
- data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
- data/ext/libyajl2/vendored/test/run_tests.sh +94 -0
- data/ext/libyajl2/vendored/test/yajl_test.c +281 -0
- data/ext/libyajl2/vendored/verify/CMakeLists.txt +39 -0
- data/ext/libyajl2/vendored/verify/json_verify.c +116 -0
- data/lib/ffi_yajl.rb +14 -0
- data/lib/ffi_yajl/benchmark.rb +7 -0
- data/lib/ffi_yajl/benchmark/MIT-LICENSE +20 -0
- data/lib/ffi_yajl/benchmark/encode.rb +135 -0
- data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +42 -0
- data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +53 -0
- data/lib/ffi_yajl/benchmark/encode_profile.rb +38 -0
- data/lib/ffi_yajl/benchmark/http.rb +32 -0
- data/lib/ffi_yajl/benchmark/parse.rb +133 -0
- data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +50 -0
- data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +55 -0
- data/lib/ffi_yajl/benchmark/parse_profile.rb +37 -0
- data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +39 -0
- data/lib/ffi_yajl/benchmark/parse_stream.rb +54 -0
- data/lib/ffi_yajl/benchmark/subjects/item.json +1 -0
- data/lib/ffi_yajl/benchmark/subjects/ohai.json +1216 -0
- data/lib/ffi_yajl/benchmark/subjects/ohai.marshal_dump +0 -0
- data/lib/ffi_yajl/benchmark/subjects/ohai.yml +975 -0
- data/lib/ffi_yajl/benchmark/subjects/twitter_search.json +1 -0
- data/lib/ffi_yajl/benchmark/subjects/twitter_stream.json +430 -0
- data/lib/ffi_yajl/benchmark/subjects/unicode.json +1 -0
- data/lib/ffi_yajl/encoder.rb +53 -0
- data/lib/ffi_yajl/ext.rb +22 -0
- data/lib/ffi_yajl/ext/.keep +0 -0
- data/lib/ffi_yajl/ffi.rb +129 -0
- data/lib/ffi_yajl/ffi/encoder.rb +175 -0
- data/lib/ffi_yajl/ffi/parser.rb +145 -0
- data/lib/ffi_yajl/json_gem.rb +121 -0
- data/lib/ffi_yajl/parser.rb +23 -0
- data/lib/ffi_yajl/version.rb +3 -0
- data/lib/libyajl.so +0 -0
- data/lib/libyajl.so.2 +0 -0
- data/lib/libyajl.so.2.0.5 +0 -0
- data/lib/libyajl_s.a +0 -0
- data/spec/ffi_yajl/encoder_spec.rb +39 -0
- data/spec/ffi_yajl/json_gem_spec.rb +355 -0
- data/spec/ffi_yajl/parser_spec.rb +78 -0
- data/spec/spec_helper.rb +14 -0
- metadata +332 -0
data/lib/ffi_yajl.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
if ENV['FORCE_FFI_YAJL'] == "ext"
|
3
|
+
require 'ffi_yajl/ext'
|
4
|
+
elsif ENV['FORCE_FFI_YAJL'] == "ffi" || defined?(Yajl) || RUBY_VERSION.to_f < 1.9
|
5
|
+
# - can't dynlink our libyajl2 c-ext and Yajl's libyajl1 c-ext into the same binary
|
6
|
+
# - c-extension segfaults on ruby 1.8.7
|
7
|
+
require 'ffi_yajl/ffi'
|
8
|
+
else
|
9
|
+
begin
|
10
|
+
require 'ffi_yajl/ext'
|
11
|
+
rescue LoadError
|
12
|
+
require 'ffi_yajl/ffi'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
|
2
|
+
# See MIT-LICENSE
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'stringio'
|
7
|
+
if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
|
8
|
+
if ENV['FORCE_FFI_YAJL'] != 'ext'
|
9
|
+
begin
|
10
|
+
require 'yajl'
|
11
|
+
rescue Exception
|
12
|
+
puts "INFO: yajl-ruby not installed"
|
13
|
+
end
|
14
|
+
else
|
15
|
+
puts "INFO: skipping yajl-ruby because we're using the C extension"
|
16
|
+
end
|
17
|
+
else
|
18
|
+
puts "INFO: skipping yajl-ruby on jruby"
|
19
|
+
end
|
20
|
+
require 'ffi_yajl'
|
21
|
+
begin
|
22
|
+
require 'json'
|
23
|
+
rescue Exception
|
24
|
+
puts "INFO: json gem not installed"
|
25
|
+
end
|
26
|
+
begin
|
27
|
+
require 'psych'
|
28
|
+
rescue Exception
|
29
|
+
puts "INFO: psych gem not installed"
|
30
|
+
end
|
31
|
+
begin
|
32
|
+
require 'active_support'
|
33
|
+
rescue Exception
|
34
|
+
puts "INFO: active_support gem not installed"
|
35
|
+
end
|
36
|
+
begin
|
37
|
+
require 'oj'
|
38
|
+
rescue Exception
|
39
|
+
puts "INFO: oj gem not installed"
|
40
|
+
end
|
41
|
+
|
42
|
+
module FFI_Yajl
|
43
|
+
class Benchmark
|
44
|
+
class Encode
|
45
|
+
|
46
|
+
def run
|
47
|
+
#filename = ARGV[0] || 'benchmark/subjects/ohai.json'
|
48
|
+
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
|
49
|
+
hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) }
|
50
|
+
|
51
|
+
times = ARGV[1] ? ARGV[1].to_i : 1000
|
52
|
+
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
|
53
|
+
::Benchmark.bmbm { |x|
|
54
|
+
|
55
|
+
x.report("FFI_Yajl::Encoder.encode (to a String)") {
|
56
|
+
times.times {
|
57
|
+
output = FFI_Yajl::Encoder.encode(hash)
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
ffi_string_encoder = FFI_Yajl::Encoder.new
|
62
|
+
x.report("FFI_Yajl::Encoder#encode (to a String)") {
|
63
|
+
times.times {
|
64
|
+
output = ffi_string_encoder.encode(hash)
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
if defined?(Oj)
|
69
|
+
x.report("Oj.dump (to a String)") {
|
70
|
+
times.times {
|
71
|
+
output = Oj.dump(hash)
|
72
|
+
}
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
if defined?(Yajl::Encoder)
|
77
|
+
x.report("Yajl::Encoder.encode (to a String)") {
|
78
|
+
times.times {
|
79
|
+
output = Yajl::Encoder.encode(hash)
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
io_encoder = Yajl::Encoder.new
|
84
|
+
x.report("Yajl::Encoder#encode (to an IO)") {
|
85
|
+
times.times {
|
86
|
+
io_encoder.encode(hash, StringIO.new)
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
string_encoder = Yajl::Encoder.new
|
91
|
+
x.report("Yajl::Encoder#encode (to a String)") {
|
92
|
+
times.times {
|
93
|
+
output = string_encoder.encode(hash)
|
94
|
+
}
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
if defined?(JSON)
|
99
|
+
x.report("JSON.generate") {
|
100
|
+
times.times {
|
101
|
+
JSON.generate(hash)
|
102
|
+
}
|
103
|
+
}
|
104
|
+
end
|
105
|
+
if defined?(Psych)
|
106
|
+
x.report("Psych.to_json") {
|
107
|
+
times.times {
|
108
|
+
Psych.to_json(hash)
|
109
|
+
}
|
110
|
+
}
|
111
|
+
if defined?(Psych::JSON::Stream)
|
112
|
+
x.report("Psych::JSON::Stream") {
|
113
|
+
times.times {
|
114
|
+
io = StringIO.new
|
115
|
+
stream = Psych::JSON::Stream.new io
|
116
|
+
stream.start
|
117
|
+
stream.push hash
|
118
|
+
stream.finish
|
119
|
+
}
|
120
|
+
}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
if defined?(ActiveSupport::JSON)
|
124
|
+
x.report("ActiveSupport::JSON.encode") {
|
125
|
+
times.times {
|
126
|
+
ActiveSupport::JSON.encode(hash)
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'yajl'
|
7
|
+
require 'stringio'
|
8
|
+
begin
|
9
|
+
require 'json'
|
10
|
+
rescue LoadError
|
11
|
+
end
|
12
|
+
|
13
|
+
times = ARGV[0] ? ARGV[0].to_i : 1000
|
14
|
+
filename = 'benchmark/subjects/ohai.json'
|
15
|
+
json = File.new(filename, 'r')
|
16
|
+
hash = Yajl::Parser.new.parse(json)
|
17
|
+
json.close
|
18
|
+
|
19
|
+
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
|
20
|
+
Benchmark.bmbm { |x|
|
21
|
+
encoder = Yajl::Encoder.new
|
22
|
+
x.report {
|
23
|
+
puts "Yajl::Encoder#encode"
|
24
|
+
times.times {
|
25
|
+
encoder.encode(hash, StringIO.new)
|
26
|
+
}
|
27
|
+
}
|
28
|
+
if defined?(JSON)
|
29
|
+
x.report {
|
30
|
+
puts "JSON's #to_json"
|
31
|
+
times.times {
|
32
|
+
JSON.generate(hash)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
x.report {
|
37
|
+
puts "Marshal.dump"
|
38
|
+
times.times {
|
39
|
+
Marshal.dump(hash)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'yajl'
|
7
|
+
begin
|
8
|
+
require 'json'
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
require 'yaml'
|
12
|
+
|
13
|
+
# JSON Section
|
14
|
+
filename = 'benchmark/subjects/ohai.json'
|
15
|
+
json = File.new(filename, 'r')
|
16
|
+
hash = Yajl::Parser.new.parse(json)
|
17
|
+
json.close
|
18
|
+
|
19
|
+
times = ARGV[0] ? ARGV[0].to_i : 1000
|
20
|
+
puts "Starting benchmark encoding #{filename} into JSON #{times} times\n\n"
|
21
|
+
Benchmark.bmbm { |x|
|
22
|
+
encoder = Yajl::Encoder.new
|
23
|
+
x.report {
|
24
|
+
puts "Yajl::Encoder#encode"
|
25
|
+
times.times {
|
26
|
+
encoder.encode(hash, StringIO.new)
|
27
|
+
}
|
28
|
+
}
|
29
|
+
if defined?(JSON)
|
30
|
+
x.report {
|
31
|
+
puts "JSON's #to_json"
|
32
|
+
times.times {
|
33
|
+
JSON.generate(hash)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
}
|
38
|
+
|
39
|
+
# YAML Section
|
40
|
+
filename = 'benchmark/subjects/ohai.yml'
|
41
|
+
yml = File.new(filename, 'r')
|
42
|
+
data = YAML.load_stream(yml)
|
43
|
+
yml.close
|
44
|
+
|
45
|
+
puts "Starting benchmark encoding #{filename} into YAML #{times} times\n\n"
|
46
|
+
Benchmark.bmbm { |x|
|
47
|
+
x.report {
|
48
|
+
puts "YAML.dump"
|
49
|
+
times.times {
|
50
|
+
YAML.dump(data, StringIO.new)
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
|
2
|
+
# See MIT-LICENSE
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'ffi_yajl'
|
6
|
+
begin
|
7
|
+
require 'perftools'
|
8
|
+
rescue Exception
|
9
|
+
puts "INFO: perftools.rb gem not installed"
|
10
|
+
end
|
11
|
+
|
12
|
+
ENV['CPUPROFILE_FREQUENCY'] = "4000"
|
13
|
+
|
14
|
+
module FFI_Yajl
|
15
|
+
class Benchmark
|
16
|
+
class EncodeProfile
|
17
|
+
|
18
|
+
def run
|
19
|
+
if defined?(PerfTools)
|
20
|
+
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
|
21
|
+
hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) }
|
22
|
+
|
23
|
+
times = 1000
|
24
|
+
puts "Starting profiling encoding #{filename} #{times} times\n\n"
|
25
|
+
|
26
|
+
ffi_string_encoder = FFI_Yajl::Encoder.new
|
27
|
+
PerfTools::CpuProfiler.start("/tmp/ffi_yajl_encode_profile.out") do
|
28
|
+
times.times {
|
29
|
+
output = ffi_string_encoder.encode(hash)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'yajl/http_stream'
|
7
|
+
require 'yajl/gzip'
|
8
|
+
require 'yajl/deflate'
|
9
|
+
require 'yajl/bzip2' unless defined?(Bzip2)
|
10
|
+
require 'json'
|
11
|
+
require 'uri'
|
12
|
+
require 'net/http'
|
13
|
+
|
14
|
+
uri = URI.parse('http://search.twitter.com/search.json?q=github')
|
15
|
+
# uri = URI.parse('http://localhost/yajl-ruby.git/benchmark/subjects/contacts.json')
|
16
|
+
|
17
|
+
times = ARGV[0] ? ARGV[0].to_i : 1
|
18
|
+
puts "Starting benchmark parsing #{uri.to_s} #{times} times\n\n"
|
19
|
+
Benchmark.bmbm { |x|
|
20
|
+
x.report {
|
21
|
+
puts "Yajl::HttpStream.get"
|
22
|
+
times.times {
|
23
|
+
Yajl::HttpStream.get(uri)
|
24
|
+
}
|
25
|
+
}
|
26
|
+
x.report {
|
27
|
+
puts "JSON.parser"
|
28
|
+
times.times {
|
29
|
+
JSON.parse(Net::HTTP.get_response(uri).body, :max_nesting => false)
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'yaml'
|
4
|
+
require 'yajl'
|
5
|
+
require 'ffi_yajl'
|
6
|
+
if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
|
7
|
+
if ENV['FORCE_FFI_YAJL'] != 'ext'
|
8
|
+
begin
|
9
|
+
require 'yajl'
|
10
|
+
rescue Exception
|
11
|
+
puts "INFO: yajl-ruby not installed"
|
12
|
+
end
|
13
|
+
else
|
14
|
+
puts "INFO: skipping yajl-ruby because we're using the C extension"
|
15
|
+
end
|
16
|
+
else
|
17
|
+
puts "INFO: skipping yajl-ruby on jruby"
|
18
|
+
end
|
19
|
+
begin
|
20
|
+
require 'json'
|
21
|
+
rescue LoadError
|
22
|
+
end
|
23
|
+
begin
|
24
|
+
require 'psych'
|
25
|
+
rescue LoadError
|
26
|
+
end
|
27
|
+
begin
|
28
|
+
require 'active_support'
|
29
|
+
rescue LoadError
|
30
|
+
end
|
31
|
+
|
32
|
+
class FFI_Yajl::Benchmark::Parse
|
33
|
+
|
34
|
+
def run
|
35
|
+
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "item.json"))
|
36
|
+
json = File.new(filename, 'r')
|
37
|
+
json_str = json.read
|
38
|
+
|
39
|
+
times = ARGV[1] ? ARGV[1].to_i : 10_000
|
40
|
+
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
|
41
|
+
Benchmark.bmbm { |x|
|
42
|
+
x.report {
|
43
|
+
puts "FFI_Yajl::Parser.parse (from a String)"
|
44
|
+
times.times {
|
45
|
+
FFI_Yajl::Parser.parse(json_str)
|
46
|
+
}
|
47
|
+
}
|
48
|
+
# ffi_parser = FFI_Yajl::Parser.new
|
49
|
+
# x.report {
|
50
|
+
# puts "FFI_Yajl::Parser#parse (from a String)"
|
51
|
+
# times.times {
|
52
|
+
# json.rewind
|
53
|
+
# ffi_parser.parse(json.read)
|
54
|
+
# }
|
55
|
+
# }
|
56
|
+
if defined?(Yajl::Parser)
|
57
|
+
x.report {
|
58
|
+
puts "Yajl::Parser.parse (from a String)"
|
59
|
+
times.times {
|
60
|
+
Yajl::Parser.parse(json_str)
|
61
|
+
}
|
62
|
+
}
|
63
|
+
io_parser = Yajl::Parser.new
|
64
|
+
io_parser.on_parse_complete = lambda {|obj|} if times > 1
|
65
|
+
x.report {
|
66
|
+
puts "Yajl::Parser#parse (from an IO)"
|
67
|
+
times.times {
|
68
|
+
json.rewind
|
69
|
+
io_parser.parse(json)
|
70
|
+
}
|
71
|
+
}
|
72
|
+
string_parser = Yajl::Parser.new
|
73
|
+
string_parser.on_parse_complete = lambda {|obj|} if times > 1
|
74
|
+
x.report {
|
75
|
+
puts "Yajl::Parser#parse (from a String)"
|
76
|
+
times.times {
|
77
|
+
json.rewind
|
78
|
+
string_parser.parse(json_str)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
end
|
82
|
+
if defined?(JSON)
|
83
|
+
x.report {
|
84
|
+
puts "JSON.parse"
|
85
|
+
times.times {
|
86
|
+
json.rewind
|
87
|
+
JSON.parse(json.read, :max_nesting => false)
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
if defined?(ActiveSupport::JSON)
|
92
|
+
x.report {
|
93
|
+
puts "ActiveSupport::JSON.decode"
|
94
|
+
times.times {
|
95
|
+
json.rewind
|
96
|
+
ActiveSupport::JSON.decode(json.read)
|
97
|
+
}
|
98
|
+
}
|
99
|
+
end
|
100
|
+
x.report {
|
101
|
+
puts "YAML.load (from an IO)"
|
102
|
+
times.times {
|
103
|
+
json.rewind
|
104
|
+
YAML.load(json)
|
105
|
+
}
|
106
|
+
}
|
107
|
+
x.report {
|
108
|
+
puts "YAML.load (from a String)"
|
109
|
+
times.times {
|
110
|
+
YAML.load(json_str)
|
111
|
+
}
|
112
|
+
}
|
113
|
+
if defined?(Psych)
|
114
|
+
x.report {
|
115
|
+
puts "Psych.load (from an IO)"
|
116
|
+
times.times {
|
117
|
+
json.rewind
|
118
|
+
Psych.load(json)
|
119
|
+
}
|
120
|
+
}
|
121
|
+
x.report {
|
122
|
+
puts "Psych.load (from a String)"
|
123
|
+
times.times {
|
124
|
+
Psych.load(json_str)
|
125
|
+
}
|
126
|
+
}
|
127
|
+
end
|
128
|
+
}
|
129
|
+
json.close
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|