ffi-yajl 2.7.5-universal-mingw-ucrt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +118 -0
  4. data/bin/ffi-yajl-bench +36 -0
  5. data/ext/ffi_yajl/ext/dlopen/dlopen.c +40 -0
  6. data/ext/ffi_yajl/ext/dlopen/extconf.rb +16 -0
  7. data/ext/ffi_yajl/ext/dlopen/yajl.sym +18 -0
  8. data/ext/ffi_yajl/ext/encoder/encoder.c +395 -0
  9. data/ext/ffi_yajl/ext/encoder/extconf.rb +86 -0
  10. data/ext/ffi_yajl/ext/parser/extconf.rb +86 -0
  11. data/ext/ffi_yajl/ext/parser/parser.c +240 -0
  12. data/lib/ffi_yajl/benchmark/MIT-LICENSE +20 -0
  13. data/lib/ffi_yajl/benchmark/encode.rb +82 -0
  14. data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +42 -0
  15. data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +47 -0
  16. data/lib/ffi_yajl/benchmark/encode_profile.rb +34 -0
  17. data/lib/ffi_yajl/benchmark/http.rb +28 -0
  18. data/lib/ffi_yajl/benchmark/parse.rb +93 -0
  19. data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +50 -0
  20. data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +55 -0
  21. data/lib/ffi_yajl/benchmark/parse_profile.rb +33 -0
  22. data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +34 -0
  23. data/lib/ffi_yajl/benchmark/parse_stream.rb +54 -0
  24. data/lib/ffi_yajl/benchmark/subjects/item.json +1 -0
  25. data/lib/ffi_yajl/benchmark/subjects/ohai.json +1216 -0
  26. data/lib/ffi_yajl/benchmark/subjects/ohai.marshal_dump +0 -0
  27. data/lib/ffi_yajl/benchmark/subjects/ohai.yml +975 -0
  28. data/lib/ffi_yajl/benchmark/subjects/twitter_search.json +1 -0
  29. data/lib/ffi_yajl/benchmark/subjects/twitter_stream.json +430 -0
  30. data/lib/ffi_yajl/benchmark/subjects/unicode.json +1 -0
  31. data/lib/ffi_yajl/benchmark.rb +27 -0
  32. data/lib/ffi_yajl/encoder.rb +94 -0
  33. data/lib/ffi_yajl/ext/.keep +0 -0
  34. data/lib/ffi_yajl/ext.rb +49 -0
  35. data/lib/ffi_yajl/ffi/encoder.rb +262 -0
  36. data/lib/ffi_yajl/ffi/parser.rb +163 -0
  37. data/lib/ffi_yajl/ffi.rb +153 -0
  38. data/lib/ffi_yajl/map_library_name.rb +109 -0
  39. data/lib/ffi_yajl/parser.rb +91 -0
  40. data/lib/ffi_yajl/platform.rb +29 -0
  41. data/lib/ffi_yajl/version.rb +25 -0
  42. data/lib/ffi_yajl.rb +50 -0
  43. metadata +128 -0
@@ -0,0 +1,93 @@
1
+ require "rubygems" unless defined?(Gem)
2
+ require "benchmark" unless defined?(Benchmark)
3
+ require "yajl"
4
+ require_relative "../../ffi_yajl"
5
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
6
+ begin
7
+ require "yajl"
8
+ rescue LoadError
9
+ puts "INFO: yajl-ruby not installed"
10
+ end
11
+ else
12
+ puts "INFO: skipping yajl-ruby on jruby"
13
+ end
14
+ begin
15
+ require "json" unless defined?(JSON)
16
+ rescue LoadError
17
+ end
18
+ begin
19
+ require "oj"
20
+ rescue LoadError
21
+ end
22
+
23
+ module FFI_Yajl
24
+ class Benchmark
25
+ class Parse
26
+ def run
27
+ filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "item.json"))
28
+ json = File.new(filename, "r")
29
+ json_str = json.read
30
+
31
+ times = ARGV[1] ? ARGV[1].to_i : 10_000
32
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
33
+ ::Benchmark.bmbm do |x|
34
+ x.report do
35
+ puts "FFI_Yajl::Parser.parse (from a String)"
36
+ times.times { FFI_Yajl::Parser.parse(json_str) }
37
+ end
38
+ # ffi_parser = FFI_Yajl::Parser.new
39
+ # x.report {
40
+ # puts "FFI_Yajl::Parser#parse (from a String)"
41
+ # times.times {
42
+ # json.rewind
43
+ # ffi_parser.parse(json.read)
44
+ # }
45
+ # }
46
+ if defined?(Yajl::Parser)
47
+ x.report do
48
+ puts "Yajl::Parser.parse (from a String)"
49
+ times.times { Yajl::Parser.parse(json_str) }
50
+ end
51
+ io_parser = Yajl::Parser.new
52
+ io_parser.on_parse_complete = ->(obj) {} if times > 1
53
+ x.report do
54
+ puts "Yajl::Parser#parse (from an IO)"
55
+ times.times do
56
+ json.rewind
57
+ io_parser.parse(json)
58
+ end
59
+ end
60
+ string_parser = Yajl::Parser.new
61
+ string_parser.on_parse_complete = ->(obj) {} if times > 1
62
+ x.report do
63
+ puts "Yajl::Parser#parse (from a String)"
64
+ times.times do
65
+ json.rewind
66
+ string_parser.parse(json_str)
67
+ end
68
+ end
69
+ end
70
+ if defined?(Oj)
71
+ x.report do
72
+ puts "Oj.load"
73
+ times.times do
74
+ json.rewind
75
+ Oj.load(json.read)
76
+ end
77
+ end
78
+ end
79
+ if defined?(JSON)
80
+ x.report do
81
+ puts "JSON.parse"
82
+ times.times do
83
+ json.rewind
84
+ JSON.parse(json.read, max_nesting: false)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ json.close
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,50 @@
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" unless defined?(Gem)
5
+ require "benchmark" unless defined?(Benchmark)
6
+ require "yajl"
7
+ begin
8
+ require "json" unless defined?(JSON)
9
+ rescue LoadError
10
+ end
11
+
12
+ # JSON section
13
+ filename = "benchmark/subjects/ohai.json"
14
+ marshal_filename = "benchmark/subjects/ohai.marshal_dump"
15
+ json = File.new(filename, "r")
16
+ marshal_file = File.new(marshal_filename, "r")
17
+
18
+ hash = {}
19
+
20
+ times = ARGV[0] ? ARGV[0].to_i : 1000
21
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
22
+ Benchmark.bmbm do |x|
23
+ x.report do
24
+ puts "Yajl::Parser#parse"
25
+ yajl = Yajl::Parser.new
26
+ yajl.on_parse_complete = ->(obj) {} if times > 1
27
+ times.times do
28
+ json.rewind
29
+ hash = yajl.parse(json)
30
+ end
31
+ end
32
+ if defined?(JSON)
33
+ x.report do
34
+ puts "JSON.parse"
35
+ times.times do
36
+ json.rewind
37
+ JSON.parse(json.read, max_nesting: false)
38
+ end
39
+ end
40
+ end
41
+ x.report do
42
+ puts "Marshal.load"
43
+ times.times do
44
+ marshal_file.rewind
45
+ Marshal.load(marshal_file)
46
+ end
47
+ end
48
+ end
49
+ json.close
50
+ marshal_file.close
@@ -0,0 +1,55 @@
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" unless defined?(Gem)
5
+ require "benchmark" unless defined?(Benchmark)
6
+ require "yajl"
7
+ begin
8
+ require "json" unless defined?(JSON)
9
+ rescue LoadError
10
+ end
11
+ require "yaml" unless defined?(YAML)
12
+
13
+ # JSON section
14
+ filename = "benchmark/subjects/ohai.json"
15
+ json = File.new(filename, "r")
16
+
17
+ times = ARGV[0] ? ARGV[0].to_i : 1000
18
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
19
+ Benchmark.bmbm do |x|
20
+ parser = Yajl::Parser.new
21
+ parser.on_parse_complete = ->(obj) {} if times > 1
22
+ x.report do
23
+ puts "Yajl::Parser#parse"
24
+ times.times do
25
+ json.rewind
26
+ parser.parse(json)
27
+ end
28
+ end
29
+ if defined?(JSON)
30
+ x.report do
31
+ puts "JSON.parse"
32
+ times.times do
33
+ json.rewind
34
+ JSON.parse(json.read, max_nesting: false)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ json.close
40
+
41
+ # YAML section
42
+ filename = "benchmark/subjects/ohai.yml"
43
+ yaml = File.new(filename, "r")
44
+
45
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of YAML data #{times} times\n\n"
46
+ Benchmark.bmbm do |x|
47
+ x.report do
48
+ puts "YAML.load_stream"
49
+ times.times do
50
+ yaml.rewind
51
+ YAML.load(yaml)
52
+ end
53
+ end
54
+ end
55
+ yaml.close
@@ -0,0 +1,33 @@
1
+ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
2
+ # See MIT-LICENSE
3
+
4
+ require "rubygems" unless defined?(Gem)
5
+ require_relative "../../ffi_yajl"
6
+ begin
7
+ require "perftools"
8
+ rescue LoadError
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 ParseProfile
17
+ def run
18
+ return if defined?(PerfTools)
19
+
20
+ filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
21
+ json = File.new(filename, "r").read
22
+
23
+ times = 1000
24
+ puts "Starting profiling encoding #{filename} #{times} times\n\n"
25
+
26
+ PerfTools::CpuProfiler.start("/tmp/ffi_yajl_encode_profile.out") do
27
+ times.times { FFI_Yajl::Parser.parse(json) }
28
+ end
29
+ system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
2
+ # See MIT-LICENSE
3
+
4
+ require "rubygems" unless defined?(Gem)
5
+ require_relative "../../ffi_yajl"
6
+
7
+ module FFI_Yajl
8
+ class Benchmark
9
+ class ParseProfileRubyProf
10
+ def run
11
+ begin
12
+ require "ruby-prof"
13
+ rescue LoadError
14
+ puts "INFO: perftools.rb gem not installed"
15
+ end
16
+
17
+ return if defined?(RubyProf)
18
+
19
+ filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
20
+ json = File.new(filename, "r").read
21
+
22
+ times = 1000
23
+ puts "Starting profiling encoding #{filename} #{times} times\n\n"
24
+
25
+ result = RubyProf.profile do
26
+ times.times { FFI_Yajl::Parser.parse(json) }
27
+ end
28
+
29
+ printer = RubyProf::GraphPrinter.new(result)
30
+ printer.print(STDOUT, {})
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
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" unless defined?(Gem)
5
+ require "benchmark" unless defined?(Benchmark)
6
+ require "yajl"
7
+ begin
8
+ require "json" unless defined?(JSON)
9
+ rescue LoadError
10
+ end
11
+ begin
12
+ require "active_support"
13
+ rescue LoadError
14
+ end
15
+
16
+ filename = "benchmark/subjects/twitter_stream.json"
17
+ json = File.new(filename, "r")
18
+
19
+ times = ARGV[0] ? ARGV[0].to_i : 100
20
+ puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n"
21
+ Benchmark.bmbm do |x|
22
+ parser = Yajl::Parser.new
23
+ parser.on_parse_complete = ->(obj) {}
24
+ x.report do
25
+ puts "Yajl::Parser#parse"
26
+ times.times do
27
+ json.rewind
28
+ parser.parse(json)
29
+ end
30
+ end
31
+ if defined?(JSON)
32
+ x.report do
33
+ puts "JSON.parse"
34
+ times.times do
35
+ json.rewind
36
+ while ( chunk = json.gets )
37
+ JSON.parse(chunk, max_nesting: false)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ if defined?(ActiveSupport::JSON)
43
+ x.report do
44
+ puts "ActiveSupport::JSON.decode"
45
+ times.times do
46
+ json.rewind
47
+ while ( chunk = json.gets )
48
+ ActiveSupport::JSON.decode(chunk)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ json.close
@@ -0,0 +1 @@
1
+ {"item": {"name": "generated", "cached_tag_list": "", "updated_at": "2009-03-24T05:25:09Z", "updated_by_id": null, "price": 1.99, "delta": false, "cost": 0.597, "account_id": 16, "unit": null, "import_tag": null, "taxable": true, "id": 1, "created_by_id": null, "description": null, "company_id": 0, "sku": "06317-0306", "created_at": "2009-03-24T05:25:09Z", "active": true}}