fast_blank_java 0.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 505346efda3547f6c25c1c73173db392936ebdb7
4
+ data.tar.gz: 0a1242135e7dbf0b603cf767e4411e73cc7f5d0d
5
+ SHA512:
6
+ metadata.gz: fafaabc6a8297cf87309a3308c264f02e1e933949881d126143367e7db986e095c6e9adb564f431c1d9aff2b8910a045c69ad07efb0d9a420177ec942466c9bb
7
+ data.tar.gz: 3d57b29a8c114049db6d8d2df42317a2907387bb3a9b56bd0b6d15c6bed6b162b1b78ddc01935bd189b255a0cbdef093d871d381c0def6132e503d17f5fb8b1b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .ruby-*
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ Gemfile.lock
11
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in fast_blank_java.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Brandon Dewitt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ProtobufJavaHelpers
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fast_blank_java`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fast_blank_java'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fast_blank_java
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fast_blank_java.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rake/javaextensiontask"
4
+
5
+ ::Rake::JavaExtensionTask.new("fast_blank_java") do |ext|
6
+ jruby_home = ENV["MY_RUBY_HOME"] # this is available of rvm
7
+ jars = ["#{jruby_home}/lib/jruby.jar"] + FileList["lib/*.jar"]
8
+ ext.classpath = jars.map { |x| File.expand_path x }.join ":"
9
+ ext.ext_dir = "ext/"
10
+ ext.lib_dir = "lib/jars"
11
+ ext.name = "fast_blank_java"
12
+ ext.source_version = "1.8"
13
+ ext.target_version = "1.8"
14
+ end
data/benchmark.rb ADDED
@@ -0,0 +1,143 @@
1
+ require 'benchmark/ips'
2
+ require 'fast_blank_java'
3
+
4
+ class String
5
+ # active support implementation
6
+ def slow_blank?
7
+ /\A[[:space:]]*\z/ === self
8
+ end
9
+
10
+ def new_slow_blank?
11
+ empty? || !(/[[:^space:]]/ === self)
12
+ end
13
+ end
14
+
15
+ test_strings = [
16
+ "",
17
+ "\r\n\r\n ",
18
+ "this is a test",
19
+ " this is a longer test",
20
+ " this is a longer test
21
+ this is a longer test
22
+ this is a longer test
23
+ this is a longer test
24
+ this is a longer test"
25
+ ]
26
+
27
+ test_strings.each do |s|
28
+ raise "failed on #{s.inspect}" if s.blank? != s.slow_blank?
29
+ raise "failed on #{s.inspect}" if s.blank? != s.new_slow_blank?
30
+ raise "failed on #{s.inspect}" if s.blank? != s.fast_blank_java?
31
+ end
32
+
33
+ test_strings.each do |s|
34
+ puts "\n================== Test String Length: #{s.length} =================="
35
+ Benchmark.ips do |x|
36
+ x.report("Fast Blank Java") do |times|
37
+ i = 0
38
+ while i < times
39
+ s.fast_blank_java?
40
+ i += 1
41
+ end
42
+ end
43
+
44
+ x.report("Slow Blank") do |times|
45
+ i = 0
46
+ while i < times
47
+ s.slow_blank?
48
+ i += 1
49
+ end
50
+ end
51
+
52
+ x.report("New Slow Blank") do |times|
53
+ i = 0
54
+ while i < times
55
+ s.new_slow_blank?
56
+ i += 1
57
+ end
58
+ end
59
+
60
+ x.compare!
61
+ end
62
+ end
63
+
64
+ # ================== Test String Length: 0 ==================
65
+ # Warming up --------------------------------------
66
+ # Fast Blank Java 284.023k i/100ms
67
+ # Slow Blank 192.986k i/100ms
68
+ # New Slow Blank 290.646k i/100ms
69
+ # Calculating -------------------------------------
70
+ # Fast Blank Java 55.900M (± 9.5%) i/s - 275.218M in 4.997932s
71
+ # Slow Blank 5.710M (± 5.9%) i/s - 28.562M in 5.021554s
72
+ # New Slow Blank 33.295M (±10.9%) i/s - 163.052M in 4.999298s
73
+ #
74
+ # Comparison:
75
+ # Fast Blank Java: 55899919.8 i/s
76
+ # New Slow Blank: 33295457.1 i/s - 1.68x slower
77
+ # Slow Blank: 5710375.9 i/s - 9.79x slower
78
+ #
79
+ #
80
+ # ================== Test String Length: 6 ==================
81
+ # Warming up --------------------------------------
82
+ # Fast Blank Java 271.907k i/100ms
83
+ # Slow Blank 142.502k i/100ms
84
+ # New Slow Blank 228.848k i/100ms
85
+ # Calculating -------------------------------------
86
+ # Fast Blank Java 29.466M (±14.0%) i/s - 143.023M in 5.004893s
87
+ # Slow Blank 2.741M (± 4.5%) i/s - 13.680M in 5.003036s
88
+ # New Slow Blank 8.713M (± 6.2%) i/s - 43.481M in 5.011576s
89
+ #
90
+ # Comparison:
91
+ # Fast Blank Java: 29466276.8 i/s
92
+ # New Slow Blank: 8713135.2 i/s - 3.38x slower
93
+ # Slow Blank: 2740917.7 i/s - 10.75x slower
94
+ #
95
+ #
96
+ # ================== Test String Length: 14 ==================
97
+ # Warming up --------------------------------------
98
+ # Fast Blank Java 288.228k i/100ms
99
+ # Slow Blank 193.662k i/100ms
100
+ # New Slow Blank 202.398k i/100ms
101
+ # Calculating -------------------------------------
102
+ # Fast Blank Java 47.185M (± 9.6%) i/s - 232.600M in 5.002948s
103
+ # Slow Blank 5.284M (± 6.9%) i/s - 26.338M in 5.013067s
104
+ # New Slow Blank 6.316M (± 3.9%) i/s - 31.574M in 5.007293s
105
+ #
106
+ # Comparison:
107
+ # Fast Blank Java: 47184936.5 i/s
108
+ # New Slow Blank: 6315863.6 i/s - 7.47x slower
109
+ # Slow Blank: 5284184.1 i/s - 8.93x slower
110
+ #
111
+ #
112
+ # ================== Test String Length: 24 ==================
113
+ # Warming up --------------------------------------
114
+ # Fast Blank Java 279.053k i/100ms
115
+ # Slow Blank 146.723k i/100ms
116
+ # New Slow Blank 201.917k i/100ms
117
+ # Calculating -------------------------------------
118
+ # Fast Blank Java 35.628M (± 9.4%) i/s - 175.803M in 5.004226s
119
+ # Slow Blank 2.979M (± 4.6%) i/s - 14.966M in 5.035114s
120
+ # New Slow Blank 6.137M (± 6.0%) i/s - 30.691M in 5.021130s
121
+ #
122
+ # Comparison:
123
+ # Fast Blank Java: 35627570.4 i/s
124
+ # New Slow Blank: 6137345.1 i/s - 5.81x slower
125
+ # Slow Blank: 2979206.5 i/s - 11.96x slower
126
+ #
127
+ #
128
+ # ================== Test String Length: 136 ==================
129
+ # Warming up --------------------------------------
130
+ # Fast Blank Java 277.245k i/100ms
131
+ # Slow Blank 148.431k i/100ms
132
+ # New Slow Blank 203.430k i/100ms
133
+ # Calculating -------------------------------------
134
+ # Fast Blank Java 35.853M (± 7.9%) i/s - 177.714M in 5.003505s
135
+ # Slow Blank 2.982M (± 5.1%) i/s - 14.992M in 5.042856s
136
+ # New Slow Blank 6.183M (± 5.0%) i/s - 30.921M in 5.015464s
137
+ #
138
+ # Comparison:
139
+ # Fast Blank Java: 35853197.9 i/s
140
+ # New Slow Blank: 6183303.9 i/s - 5.80x slower
141
+ # Slow Blank: 2982078.8 i/s - 12.02x slower
142
+ #
143
+ #
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fast_blank_java"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,81 @@
1
+ package com.abrandoned.fast_blank_java;
2
+
3
+ import java.io.IOException;
4
+ import java.io.InputStream;
5
+ import java.lang.CharSequence;
6
+ import org.jcodings.Encoding;
7
+ import org.jcodings.specific.ASCIIEncoding;
8
+ import org.jruby.Ruby;
9
+ import org.jruby.RubyString;
10
+ import org.jruby.util.io.EncodingUtils;
11
+ import org.jruby.RubyIO;
12
+ import org.jruby.ext.stringio.StringIO;
13
+ import org.jruby.util.ByteList;
14
+ import org.jruby.anno.JRubyMethod;
15
+ import org.jruby.runtime.ThreadContext;
16
+ import org.jruby.runtime.builtin.IRubyObject;
17
+
18
+ public class FastBlankJava {
19
+ @JRubyMethod(name = { "fast_blank_java?", "blank?" })
20
+ public static IRubyObject fast_blank_as_java_p(ThreadContext context, IRubyObject self) {
21
+ org.jruby.Ruby runtime = context.getRuntime();
22
+
23
+ if (self instanceof RubyString) {
24
+ org.jruby.RubyString rubyString = ((RubyString) self);
25
+ if (rubyString.isEmpty()) {
26
+ return runtime.getTrue();
27
+ }
28
+
29
+ ByteList blankValue = rubyString.getByteList();
30
+ byte[] stringBytes = blankValue.unsafeBytes();
31
+ org.jcodings.Encoding enc = rubyString.getEncoding();
32
+ int begin = blankValue.begin();
33
+ int size = blankValue.length();
34
+ int begin_plus_size = begin + size;
35
+ int next_char = begin;
36
+ int codepoint = 0;
37
+ int[] len_p = {0};
38
+
39
+ while(next_char < begin_plus_size) {
40
+ codepoint = EncodingUtils.encCodepointLength(stringBytes, next_char, begin + size, len_p, enc);
41
+
42
+ switch(codepoint) {
43
+ case 9:
44
+ case 0xa:
45
+ case 0xb:
46
+ case 0xc:
47
+ case 0xd:
48
+ case 0x20:
49
+ case 0x85:
50
+ case 0xa0:
51
+ case 0x1680:
52
+ case 0x2000:
53
+ case 0x2001:
54
+ case 0x2002:
55
+ case 0x2003:
56
+ case 0x2004:
57
+ case 0x2005:
58
+ case 0x2006:
59
+ case 0x2007:
60
+ case 0x2008:
61
+ case 0x2009:
62
+ case 0x200a:
63
+ case 0x2028:
64
+ case 0x2029:
65
+ case 0x202f:
66
+ case 0x205f:
67
+ case 0x3000:
68
+ break;
69
+ default:
70
+ return runtime.getFalse();
71
+ }
72
+
73
+ next_char += len_p[0];
74
+ }
75
+
76
+ return runtime.getTrue();
77
+ }
78
+
79
+ throw context.getRuntime().newTypeError("can't #fast_blank_java? a non-string object");
80
+ }
81
+ }
@@ -0,0 +1,20 @@
1
+ package com.abrandoned.fast_blank_java;
2
+
3
+ import org.jruby.Ruby;
4
+ import org.jruby.RubyModule;
5
+ import org.jruby.runtime.load.BasicLibraryService;
6
+ import com.abrandoned.fast_blank_java.*;
7
+
8
+ import java.io.IOException;
9
+
10
+ public class FastBlankJavaService implements BasicLibraryService {
11
+ @Override
12
+ public boolean basicLoad(final Ruby runtime) throws IOException {
13
+ RubyModule protobuf_java_helpers = runtime.getModule("FastBlankJava");
14
+
15
+ RubyModule varinter = protobuf_java_helpers.defineModuleUnder(FastBlankJava.class.getSimpleName());
16
+ varinter.defineAnnotatedMethods(FastBlankJava.class);
17
+
18
+ return true;
19
+ }
20
+ }
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fast_blank_java/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fast_blank_java"
8
+ spec.version = FastBlankJava::VERSION
9
+ spec.authors = ["Brandon Dewitt"]
10
+ spec.email = ["brandonsdewitt@gmail.com"]
11
+
12
+ spec.summary = %q{ an attempt at a fast_blank for JRuby }
13
+ spec.description = %q{ an attempt at a fast_blank for JRuby }
14
+ spec.homepage = "https://github.com/abrandoned/fast_blank_java"
15
+ spec.license = "MIT"
16
+ spec.platform = "java"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "benchmark-ips"
37
+ spec.add_development_dependency "bundler", "~> 1.16"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "minitest", "~> 5.0"
40
+ spec.add_development_dependency "rake-compiler"
41
+ end
@@ -0,0 +1,14 @@
1
+ require "java"
2
+ require "jruby"
3
+ require "fast_blank_java/version"
4
+
5
+ module FastBlankJava
6
+ # Your code goes here...
7
+ end
8
+
9
+ require "jars/fast_blank_java.jar"
10
+ com.abrandoned.fast_blank_java.FastBlankJavaService.new.basicLoad(::JRuby.runtime)
11
+
12
+ class String
13
+ include ::FastBlankJava::FastBlankJava
14
+ end
@@ -0,0 +1,3 @@
1
+ module FastBlankJava
2
+ VERSION = "0.0.1"
3
+ end
Binary file
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fast_blank_java
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: java
6
+ authors:
7
+ - Brandon Dewitt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ name: benchmark-ips
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.16'
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ name: minitest
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ name: rake-compiler
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: " an attempt at a fast_blank for JRuby "
84
+ email:
85
+ - brandonsdewitt@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - benchmark.rb
96
+ - bin/console
97
+ - bin/setup
98
+ - ext/fast_blank_java/FastBlankJava.java
99
+ - ext/fast_blank_java/FastBlankJavaService.java
100
+ - fast_blank_java.gemspec
101
+ - lib/fast_blank_java.rb
102
+ - lib/fast_blank_java/version.rb
103
+ - lib/jars/fast_blank_java.jar
104
+ homepage: https://github.com/abrandoned/fast_blank_java
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.14.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: an attempt at a fast_blank for JRuby
129
+ test_files: []