fast_blank 1.0.0 → 1.0.1
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.
- checksums.yaml +5 -5
- data/README.md +117 -37
- data/benchmark +138 -29
- data/ext/fast_blank/fast_blank.c +7 -19
- data/spec/fast_blank_spec.rb +8 -1
- metadata +20 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: a46e29b33d568838d32c4610aee3abe0c747a3a7e51ed6d68fab8583898d8abb
         | 
| 4 | 
            +
              data.tar.gz: 2a2f40409b7f03a01e05eedcbab8291580e4fb56ebf49cad9a77f9dc19273fa6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 07f48b8d905e801cf320544001a351b5ebb671225a7a9eeba0248f14405cc9981e26b365f1c27a08636dd0379b9522599df556b0ad13e59435abffb557240336
         | 
| 7 | 
            +
              data.tar.gz: e9cd3ec4d02c9b8a395432308c4cfc020374597f53852b255d55630e6929772bb07a4d2978852f90d15c9ec67f662323ded9dfaa5bb252b992957706b0fb92fc
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,66 +1,146 @@ | |
| 1 | 
            -
            ### String | 
| 1 | 
            +
            ### `String#blank?` Ruby Extension
         | 
| 2 2 |  | 
| 3 3 | 
             
            [](http://badge.fury.io/rb/fast_blank) [](https://travis-ci.org/SamSaffron/fast_blank)
         | 
| 4 4 |  | 
| 5 | 
            -
            `fast_blank` is a simple extension which provides a fast implementation of  | 
| 5 | 
            +
            `fast_blank` is a simple C extension which provides a fast implementation of [Active Support's `String#blank?` method](http://api.rubyonrails.org/classes/String.html#method-i-blank-3F).
         | 
| 6 6 |  | 
| 7 7 | 
             
            ### How do you use it?
         | 
| 8 8 |  | 
| 9 9 | 
             
                require 'fast_blank'
         | 
| 10 10 |  | 
| 11 | 
            -
             | 
| 11 | 
            +
            or add it to your Bundler Gemfile
         | 
| 12 12 |  | 
| 13 | 
            +
                gem 'fast_blank'
         | 
| 13 14 |  | 
| 14 | 
            -
             | 
| 15 | 
            +
            ### How fast is "Fast"?
         | 
| 15 16 |  | 
| 16 | 
            -
             | 
| 17 | 
            +
            About 1.2–20x faster than Active Support on my machine (your mileage my vary, depends on string length):
         | 
| 17 18 |  | 
| 18 19 | 
             
            ```
         | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
            Fast  | 
| 25 | 
            -
             | 
| 26 | 
            -
            Slow Blank | 
| 27 | 
            -
             | 
| 28 | 
            -
            Fast Blank ( | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
            Fast Blank  | 
| 35 | 
            -
             | 
| 20 | 
            +
            $ bundle exec ./benchmark
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            ================== Test String Length: 0 ==================
         | 
| 23 | 
            +
            Calculating -------------------------------------
         | 
| 24 | 
            +
                      Fast Blank   225.251k i/100ms
         | 
| 25 | 
            +
              Fast ActiveSupport   225.676k i/100ms
         | 
| 26 | 
            +
                      Slow Blank   110.934k i/100ms
         | 
| 27 | 
            +
                  New Slow Blank   221.792k i/100ms
         | 
| 28 | 
            +
            -------------------------------------------------
         | 
| 29 | 
            +
                      Fast Blank     29.673M (± 2.7%) i/s -    148.215M
         | 
| 30 | 
            +
              Fast ActiveSupport     28.249M (± 3.5%) i/s -    141.048M
         | 
| 31 | 
            +
                      Slow Blank      2.158M (± 3.3%) i/s -     10.872M
         | 
| 32 | 
            +
                  New Slow Blank     23.558M (± 3.2%) i/s -    117.772M
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            Comparison:
         | 
| 35 | 
            +
                      Fast Blank: 29673200.1 i/s
         | 
| 36 | 
            +
              Fast ActiveSupport: 28248894.5 i/s - 1.05x slower
         | 
| 37 | 
            +
                  New Slow Blank: 23557900.0 i/s - 1.26x slower
         | 
| 38 | 
            +
                      Slow Blank:  2157787.7 i/s - 13.75x slower
         | 
| 39 | 
            +
             | 
| 40 | 
            +
             | 
| 41 | 
            +
            ================== Test String Length: 6 ==================
         | 
| 42 | 
            +
            Calculating -------------------------------------
         | 
| 43 | 
            +
                      Fast Blank   201.185k i/100ms
         | 
| 44 | 
            +
              Fast ActiveSupport   205.076k i/100ms
         | 
| 45 | 
            +
                      Slow Blank   102.061k i/100ms
         | 
| 46 | 
            +
                  New Slow Blank   123.087k i/100ms
         | 
| 47 | 
            +
            -------------------------------------------------
         | 
| 48 | 
            +
                      Fast Blank     13.894M (± 2.3%) i/s -     69.409M
         | 
| 49 | 
            +
              Fast ActiveSupport     14.627M (± 3.5%) i/s -     73.212M
         | 
| 50 | 
            +
                      Slow Blank      1.943M (± 2.3%) i/s -      9.798M
         | 
| 51 | 
            +
                  New Slow Blank      2.796M (± 1.8%) i/s -     14.032M
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            Comparison:
         | 
| 54 | 
            +
              Fast ActiveSupport: 14627063.7 i/s
         | 
| 55 | 
            +
                      Fast Blank: 13893631.2 i/s - 1.05x slower
         | 
| 56 | 
            +
                  New Slow Blank:  2795783.3 i/s - 5.23x slower
         | 
| 57 | 
            +
                      Slow Blank:  1943025.9 i/s - 7.53x slower
         | 
| 58 | 
            +
             | 
| 59 | 
            +
             | 
| 60 | 
            +
            ================== Test String Length: 14 ==================
         | 
| 61 | 
            +
            Calculating -------------------------------------
         | 
| 62 | 
            +
                      Fast Blank   220.004k i/100ms
         | 
| 63 | 
            +
              Fast ActiveSupport   219.716k i/100ms
         | 
| 64 | 
            +
                      Slow Blank   147.399k i/100ms
         | 
| 65 | 
            +
                  New Slow Blank   106.651k i/100ms
         | 
| 66 | 
            +
            -------------------------------------------------
         | 
| 67 | 
            +
                      Fast Blank     24.949M (± 3.0%) i/s -    124.742M
         | 
| 68 | 
            +
              Fast ActiveSupport     24.491M (± 3.3%) i/s -    122.382M
         | 
| 69 | 
            +
                      Slow Blank      4.292M (± 1.6%) i/s -     21.520M
         | 
| 70 | 
            +
                  New Slow Blank      2.115M (± 2.4%) i/s -     10.665M
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            Comparison:
         | 
| 73 | 
            +
                      Fast Blank: 24948558.8 i/s
         | 
| 74 | 
            +
              Fast ActiveSupport: 24491245.1 i/s - 1.02x slower
         | 
| 75 | 
            +
                      Slow Blank:  4292490.5 i/s - 5.81x slower
         | 
| 76 | 
            +
                  New Slow Blank:  2115097.6 i/s - 11.80x slower
         | 
| 77 | 
            +
             | 
| 78 | 
            +
             | 
| 79 | 
            +
            ================== Test String Length: 24 ==================
         | 
| 80 | 
            +
            Calculating -------------------------------------
         | 
| 81 | 
            +
                      Fast Blank   206.555k i/100ms
         | 
| 82 | 
            +
              Fast ActiveSupport   208.513k i/100ms
         | 
| 83 | 
            +
                      Slow Blank   137.733k i/100ms
         | 
| 84 | 
            +
                  New Slow Blank   101.215k i/100ms
         | 
| 85 | 
            +
            -------------------------------------------------
         | 
| 86 | 
            +
                      Fast Blank     16.761M (± 2.7%) i/s -     83.861M
         | 
| 87 | 
            +
              Fast ActiveSupport     17.710M (± 3.2%) i/s -     88.618M
         | 
| 88 | 
            +
                      Slow Blank      3.744M (± 2.0%) i/s -     18.732M
         | 
| 89 | 
            +
                  New Slow Blank      1.962M (± 2.7%) i/s -      9.818M
         | 
| 90 | 
            +
             | 
| 91 | 
            +
            Comparison:
         | 
| 92 | 
            +
              Fast ActiveSupport: 17709936.5 i/s
         | 
| 93 | 
            +
                      Fast Blank: 16760839.7 i/s - 1.06x slower
         | 
| 94 | 
            +
                      Slow Blank:  3744048.4 i/s - 4.73x slower
         | 
| 95 | 
            +
                  New Slow Blank:  1961831.1 i/s - 9.03x slower
         | 
| 96 | 
            +
             | 
| 97 | 
            +
             | 
| 98 | 
            +
            ================== Test String Length: 136 ==================
         | 
| 99 | 
            +
            Calculating -------------------------------------
         | 
| 100 | 
            +
                      Fast Blank   201.772k i/100ms
         | 
| 101 | 
            +
              Fast ActiveSupport   189.120k i/100ms
         | 
| 102 | 
            +
                      Slow Blank   129.439k i/100ms
         | 
| 103 | 
            +
                  New Slow Blank    90.677k i/100ms
         | 
| 104 | 
            +
            -------------------------------------------------
         | 
| 105 | 
            +
                      Fast Blank     16.718M (± 2.8%) i/s -     83.534M
         | 
| 106 | 
            +
              Fast ActiveSupport     17.617M (± 3.6%) i/s -     87.941M
         | 
| 107 | 
            +
                      Slow Blank      3.725M (± 3.0%) i/s -     18.639M
         | 
| 108 | 
            +
                  New Slow Blank      1.940M (± 4.8%) i/s -      9.702M
         | 
| 109 | 
            +
             | 
| 110 | 
            +
            Comparison:
         | 
| 111 | 
            +
              Fast ActiveSupport: 17616782.1 i/s
         | 
| 112 | 
            +
                      Fast Blank: 16718307.8 i/s - 1.05x slower
         | 
| 113 | 
            +
                      Slow Blank:  3725097.6 i/s - 4.73x slower
         | 
| 114 | 
            +
                  New Slow Blank:  1940271.2 i/s - 9.08x slower
         | 
| 36 115 |  | 
| 37 116 |  | 
| 38 117 | 
             
            ```
         | 
| 39 118 |  | 
| 40 | 
            -
             | 
| 41 119 | 
             
            Additionally, this gem allocates no strings during the test, making it less of a GC burden.
         | 
| 42 120 |  | 
| 121 | 
            +
            ### Compatibility note:
         | 
| 43 122 |  | 
| 44 | 
            -
             | 
| 123 | 
            +
            `fast_blank` supports MRI Ruby 1.9.3, 2.0, 2.1, and 2.2, as well as Rubinius 2.x. Earlier versions of MRI are untested.
         | 
| 45 124 |  | 
| 46 | 
            -
            fast_blank  | 
| 125 | 
            +
            `fast_blank` implements `String#blank?` as MRI would have implemented it, meaning it has 100% parity with `String#strip.length == 0`.
         | 
| 47 126 |  | 
| 48 | 
            -
             | 
| 127 | 
            +
            Active Support's version also considers Unicode spaces.  For example, `"\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000".blank?` is true in Active Support even though `fast_blank` would treat it as *not* blank.  Therefore, `fast_blank` also provides `blank_as?` which is a 100%-compatible Active Support `blank?` replacement.
         | 
| 49 128 |  | 
| 129 | 
            +
            ### Credits
         | 
| 50 130 |  | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 131 | 
            +
            * Author: Sam Saffron (sam.saffron@gmail.com)
         | 
| 132 | 
            +
            * https://github.com/SamSaffron/fast_blank
         | 
| 133 | 
            +
            * License: MIT
         | 
| 134 | 
            +
            * Gem template based on [CodeMonkeySteve/fast_xor](https://github.com/CodeMonkeySteve/fast_xor)
         | 
| 53 135 |  | 
| 54 | 
            -
             | 
| 136 | 
            +
            ### Change log:
         | 
| 55 137 |  | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
            License: MIT  
         | 
| 138 | 
            +
            1.0.1:
         | 
| 139 | 
            +
              - Minor, avoid warnings if redefining blank?
         | 
| 59 140 |  | 
| 60 | 
            -
             | 
| 141 | 
            +
            1.0.0:
         | 
| 142 | 
            +
              - Adds Ruby 2.2 support ([@tjschuck](https://github.com/tjschuck) — [#9](https://github.com/SamSaffron/fast_blank/pull/9))
         | 
| 61 143 |  | 
| 62 144 | 
             
            0.0.2:
         | 
| 63 | 
            -
              - Removed rake dependency (tmm1)
         | 
| 64 | 
            -
              - Unrolled internal loop to improve perf (tmm1)
         | 
| 65 | 
            -
             | 
| 66 | 
            -
            (gem template based on https://github.com/CodeMonkeySteve/fast_xor )
         | 
| 145 | 
            +
              - Removed rake dependency ([@tmm1](https://github.com/tmm1) — [#2](https://github.com/SamSaffron/fast_blank/pull/2))
         | 
| 146 | 
            +
              - Unrolled internal loop to improve perf ([@tmm1](https://github.com/tmm1) — [#2](https://github.com/SamSaffron/fast_blank/pull/2))
         | 
    
        data/benchmark
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 2 | 
             
            $: << File.dirname(__FILE__)+'/lib'
         | 
| 3 | 
            -
            require 'benchmark'
         | 
| 3 | 
            +
            require 'benchmark/ips'
         | 
| 4 4 | 
             
            require 'fast_blank'
         | 
| 5 5 |  | 
| 6 6 | 
             
            class String
         | 
| @@ -8,13 +8,13 @@ class String | |
| 8 8 | 
             
              def slow_blank?
         | 
| 9 9 | 
             
                /\A[[:space:]]*\z/ === self
         | 
| 10 10 | 
             
              end
         | 
| 11 | 
            -
            end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
            n = 1000000
         | 
| 15 11 |  | 
| 12 | 
            +
              def new_slow_blank?
         | 
| 13 | 
            +
                empty? || !(/[[:^space:]]/ === self)
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| 16 16 |  | 
| 17 | 
            -
             | 
| 17 | 
            +
            test_strings = [
         | 
| 18 18 | 
             
              "",
         | 
| 19 19 | 
             
              "\r\n\r\n  ",
         | 
| 20 20 | 
             
              "this is a test",
         | 
| @@ -26,32 +26,141 @@ strings = [ | |
| 26 26 | 
             
                  this is a longer test"
         | 
| 27 27 | 
             
            ]
         | 
| 28 28 |  | 
| 29 | 
            -
             | 
| 29 | 
            +
            test_strings.each do |s|
         | 
| 30 30 | 
             
              raise "failed on #{s.inspect}" if s.blank? != s.slow_blank?
         | 
| 31 | 
            +
              raise "failed on #{s.inspect}" if s.blank? != s.new_slow_blank?
         | 
| 31 32 | 
             
            end
         | 
| 32 33 |  | 
| 33 | 
            -
             | 
| 34 | 
            -
               | 
| 35 | 
            -
             | 
| 36 | 
            -
                x.report("Fast Blank | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 34 | 
            +
            test_strings.each do |s|
         | 
| 35 | 
            +
              puts "\n================== Test String Length: #{s.length} =================="
         | 
| 36 | 
            +
              Benchmark.ips do |x|
         | 
| 37 | 
            +
                x.report("Fast Blank") do |times|
         | 
| 38 | 
            +
                  i = 0
         | 
| 39 | 
            +
                  while i < times
         | 
| 40 | 
            +
                    s.blank?
         | 
| 41 | 
            +
                    i += 1
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                x.report("Fast ActiveSupport") do |times|
         | 
| 46 | 
            +
                  i = 0
         | 
| 47 | 
            +
                  while i < times
         | 
| 48 | 
            +
                    s.blank_as?
         | 
| 49 | 
            +
                    i += 1
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                x.report("Slow Blank") do |times|
         | 
| 54 | 
            +
                  i = 0
         | 
| 55 | 
            +
                  while i < times
         | 
| 56 | 
            +
                    s.slow_blank?
         | 
| 57 | 
            +
                    i += 1
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                x.report("New Slow Blank") do |times|
         | 
| 62 | 
            +
                  i = 0
         | 
| 63 | 
            +
                  while i < times
         | 
| 64 | 
            +
                    s.new_slow_blank?
         | 
| 65 | 
            +
                    i += 1
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                x.compare!
         | 
| 39 70 | 
             
              end
         | 
| 40 71 | 
             
            end
         | 
| 41 72 |  | 
| 42 | 
            -
            # | 
| 43 | 
            -
            #  | 
| 44 | 
            -
            # | 
| 45 | 
            -
            #  | 
| 46 | 
            -
            #  | 
| 47 | 
            -
            #  | 
| 48 | 
            -
            #  | 
| 49 | 
            -
            # | 
| 50 | 
            -
            # | 
| 51 | 
            -
            # | 
| 52 | 
            -
            #  | 
| 53 | 
            -
            # | 
| 54 | 
            -
            #  | 
| 55 | 
            -
            # | 
| 56 | 
            -
            # | 
| 57 | 
            -
            # Slow Blank  | 
| 73 | 
            +
            # ================== Test String Length: 0 ==================
         | 
| 74 | 
            +
            # Calculating -------------------------------------
         | 
| 75 | 
            +
            #           Fast Blank   225.251k i/100ms
         | 
| 76 | 
            +
            #   Fast ActiveSupport   225.676k i/100ms
         | 
| 77 | 
            +
            #           Slow Blank   110.934k i/100ms
         | 
| 78 | 
            +
            #       New Slow Blank   221.792k i/100ms
         | 
| 79 | 
            +
            # -------------------------------------------------
         | 
| 80 | 
            +
            #           Fast Blank     29.673M (± 2.7%) i/s -    148.215M
         | 
| 81 | 
            +
            #   Fast ActiveSupport     28.249M (± 3.5%) i/s -    141.048M
         | 
| 82 | 
            +
            #           Slow Blank      2.158M (± 3.3%) i/s -     10.872M
         | 
| 83 | 
            +
            #       New Slow Blank     23.558M (± 3.2%) i/s -    117.772M
         | 
| 84 | 
            +
            #
         | 
| 85 | 
            +
            # Comparison:
         | 
| 86 | 
            +
            #           Fast Blank: 29673200.1 i/s
         | 
| 87 | 
            +
            #   Fast ActiveSupport: 28248894.5 i/s - 1.05x slower
         | 
| 88 | 
            +
            #       New Slow Blank: 23557900.0 i/s - 1.26x slower
         | 
| 89 | 
            +
            #           Slow Blank:  2157787.7 i/s - 13.75x slower
         | 
| 90 | 
            +
            #
         | 
| 91 | 
            +
            #
         | 
| 92 | 
            +
            # ================== Test String Length: 6 ==================
         | 
| 93 | 
            +
            # Calculating -------------------------------------
         | 
| 94 | 
            +
            #           Fast Blank   201.185k i/100ms
         | 
| 95 | 
            +
            #   Fast ActiveSupport   205.076k i/100ms
         | 
| 96 | 
            +
            #           Slow Blank   102.061k i/100ms
         | 
| 97 | 
            +
            #       New Slow Blank   123.087k i/100ms
         | 
| 98 | 
            +
            # -------------------------------------------------
         | 
| 99 | 
            +
            #           Fast Blank     13.894M (± 2.3%) i/s -     69.409M
         | 
| 100 | 
            +
            #   Fast ActiveSupport     14.627M (± 3.5%) i/s -     73.212M
         | 
| 101 | 
            +
            #           Slow Blank      1.943M (± 2.3%) i/s -      9.798M
         | 
| 102 | 
            +
            #       New Slow Blank      2.796M (± 1.8%) i/s -     14.032M
         | 
| 103 | 
            +
            #
         | 
| 104 | 
            +
            # Comparison:
         | 
| 105 | 
            +
            #   Fast ActiveSupport: 14627063.7 i/s
         | 
| 106 | 
            +
            #           Fast Blank: 13893631.2 i/s - 1.05x slower
         | 
| 107 | 
            +
            #       New Slow Blank:  2795783.3 i/s - 5.23x slower
         | 
| 108 | 
            +
            #           Slow Blank:  1943025.9 i/s - 7.53x slower
         | 
| 109 | 
            +
            #
         | 
| 110 | 
            +
            #
         | 
| 111 | 
            +
            # ================== Test String Length: 14 ==================
         | 
| 112 | 
            +
            # Calculating -------------------------------------
         | 
| 113 | 
            +
            #           Fast Blank   220.004k i/100ms
         | 
| 114 | 
            +
            #   Fast ActiveSupport   219.716k i/100ms
         | 
| 115 | 
            +
            #           Slow Blank   147.399k i/100ms
         | 
| 116 | 
            +
            #       New Slow Blank   106.651k i/100ms
         | 
| 117 | 
            +
            # -------------------------------------------------
         | 
| 118 | 
            +
            #           Fast Blank     24.949M (± 3.0%) i/s -    124.742M
         | 
| 119 | 
            +
            #   Fast ActiveSupport     24.491M (± 3.3%) i/s -    122.382M
         | 
| 120 | 
            +
            #           Slow Blank      4.292M (± 1.6%) i/s -     21.520M
         | 
| 121 | 
            +
            #       New Slow Blank      2.115M (± 2.4%) i/s -     10.665M
         | 
| 122 | 
            +
            #
         | 
| 123 | 
            +
            # Comparison:
         | 
| 124 | 
            +
            #           Fast Blank: 24948558.8 i/s
         | 
| 125 | 
            +
            #   Fast ActiveSupport: 24491245.1 i/s - 1.02x slower
         | 
| 126 | 
            +
            #           Slow Blank:  4292490.5 i/s - 5.81x slower
         | 
| 127 | 
            +
            #       New Slow Blank:  2115097.6 i/s - 11.80x slower
         | 
| 128 | 
            +
            #
         | 
| 129 | 
            +
            #
         | 
| 130 | 
            +
            # ================== Test String Length: 24 ==================
         | 
| 131 | 
            +
            # Calculating -------------------------------------
         | 
| 132 | 
            +
            #           Fast Blank   206.555k i/100ms
         | 
| 133 | 
            +
            #   Fast ActiveSupport   208.513k i/100ms
         | 
| 134 | 
            +
            #           Slow Blank   137.733k i/100ms
         | 
| 135 | 
            +
            #       New Slow Blank   101.215k i/100ms
         | 
| 136 | 
            +
            # -------------------------------------------------
         | 
| 137 | 
            +
            #           Fast Blank     16.761M (± 2.7%) i/s -     83.861M
         | 
| 138 | 
            +
            #   Fast ActiveSupport     17.710M (± 3.2%) i/s -     88.618M
         | 
| 139 | 
            +
            #           Slow Blank      3.744M (± 2.0%) i/s -     18.732M
         | 
| 140 | 
            +
            #       New Slow Blank      1.962M (± 2.7%) i/s -      9.818M
         | 
| 141 | 
            +
            #
         | 
| 142 | 
            +
            # Comparison:
         | 
| 143 | 
            +
            #   Fast ActiveSupport: 17709936.5 i/s
         | 
| 144 | 
            +
            #           Fast Blank: 16760839.7 i/s - 1.06x slower
         | 
| 145 | 
            +
            #           Slow Blank:  3744048.4 i/s - 4.73x slower
         | 
| 146 | 
            +
            #       New Slow Blank:  1961831.1 i/s - 9.03x slower
         | 
| 147 | 
            +
            #
         | 
| 148 | 
            +
            #
         | 
| 149 | 
            +
            # ================== Test String Length: 136 ==================
         | 
| 150 | 
            +
            # Calculating -------------------------------------
         | 
| 151 | 
            +
            #           Fast Blank   201.772k i/100ms
         | 
| 152 | 
            +
            #   Fast ActiveSupport   189.120k i/100ms
         | 
| 153 | 
            +
            #           Slow Blank   129.439k i/100ms
         | 
| 154 | 
            +
            #       New Slow Blank    90.677k i/100ms
         | 
| 155 | 
            +
            # -------------------------------------------------
         | 
| 156 | 
            +
            #           Fast Blank     16.718M (± 2.8%) i/s -     83.534M
         | 
| 157 | 
            +
            #   Fast ActiveSupport     17.617M (± 3.6%) i/s -     87.941M
         | 
| 158 | 
            +
            #           Slow Blank      3.725M (± 3.0%) i/s -     18.639M
         | 
| 159 | 
            +
            #       New Slow Blank      1.940M (± 4.8%) i/s -      9.702M
         | 
| 160 | 
            +
            #
         | 
| 161 | 
            +
            # Comparison:
         | 
| 162 | 
            +
            #   Fast ActiveSupport: 17616782.1 i/s
         | 
| 163 | 
            +
            #           Fast Blank: 16718307.8 i/s - 1.05x slower
         | 
| 164 | 
            +
            #           Slow Blank:  3725097.6 i/s - 4.73x slower
         | 
| 165 | 
            +
            #       New Slow Blank:  1940271.2 i/s - 9.08x slower
         | 
| 166 | 
            +
            #
         | 
    
        data/ext/fast_blank/fast_blank.c
    CHANGED
    
    | @@ -6,24 +6,11 @@ | |
| 6 6 |  | 
| 7 7 | 
             
            #define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
         | 
| 8 8 |  | 
| 9 | 
            -
             | 
| 10 | 
            -
            # | 
| 11 | 
            -
            # | 
| 9 | 
            +
            #ifndef RUBY_API_VERSION_CODE
         | 
| 10 | 
            +
            # define ruby_version_before_2_2() 1
         | 
| 11 | 
            +
            #else
         | 
| 12 | 
            +
            # define ruby_version_before_2_2() (RUBY_API_VERSION_CODE < 20200)
         | 
| 12 13 | 
             
            #endif
         | 
| 13 | 
            -
            #ifndef RSTRING_LEN
         | 
| 14 | 
            -
            #define RSTRING_LEN(s) (RSTRING(s)->len)
         | 
| 15 | 
            -
            #endif
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            static int
         | 
| 18 | 
            -
            ruby_version_before_2_2()
         | 
| 19 | 
            -
            {
         | 
| 20 | 
            -
              #ifdef RUBY_API_VERSION_MAJOR
         | 
| 21 | 
            -
              if (RUBY_API_VERSION_MAJOR > 2 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 2)) {
         | 
| 22 | 
            -
                return 0;
         | 
| 23 | 
            -
              }
         | 
| 24 | 
            -
              #endif
         | 
| 25 | 
            -
              return 1;
         | 
| 26 | 
            -
            }
         | 
| 27 14 |  | 
| 28 15 | 
             
            static VALUE
         | 
| 29 16 | 
             
            rb_str_blank_as(VALUE str)
         | 
| @@ -66,10 +53,11 @@ rb_str_blank_as(VALUE str) | |
| 66 53 | 
             
                  case 0x202f:
         | 
| 67 54 | 
             
                  case 0x205f:
         | 
| 68 55 | 
             
                  case 0x3000:
         | 
| 56 | 
            +
            #if ruby_version_before_2_2()
         | 
| 57 | 
            +
                  case 0x180e:
         | 
| 58 | 
            +
            #endif
         | 
| 69 59 | 
             
                      /* found */
         | 
| 70 60 | 
             
                      break;
         | 
| 71 | 
            -
                  case 0x180e:
         | 
| 72 | 
            -
                      if (ruby_version_before_2_2()) break;
         | 
| 73 61 | 
             
                  default:
         | 
| 74 62 | 
             
                      return Qfalse;
         | 
| 75 63 | 
             
                }
         | 
    
        data/spec/fast_blank_spec.rb
    CHANGED
    
    | @@ -1,11 +1,18 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            $VERBOSE = true
         | 
| 2 2 |  | 
| 3 3 | 
             
            class ::String
         | 
| 4 | 
            +
              # Stub the original method to make sure it is redefined correctly.
         | 
| 5 | 
            +
              def blank?
         | 
| 6 | 
            +
                raise NotImplementedError
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 4 9 | 
             
              def blank2?
         | 
| 5 10 | 
             
                /\A[[:space:]]*\z/ === self
         | 
| 6 11 | 
             
              end
         | 
| 7 12 | 
             
            end
         | 
| 8 13 |  | 
| 14 | 
            +
            require 'fast_blank'
         | 
| 15 | 
            +
             | 
| 9 16 | 
             
            describe String do
         | 
| 10 17 | 
             
              it "works" do
         | 
| 11 18 | 
             
                expect("".blank?).to eq(true)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: fast_blank
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sam Saffron
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-08-17 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rake-compiler
         | 
| @@ -38,6 +38,20 @@ dependencies: | |
| 38 38 | 
             
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: benchmark-ips
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 41 55 | 
             
            description: Provides a C-optimized method for determining if a string is blank
         | 
| 42 56 | 
             
            email: sam.saffron@gmail.com
         | 
| 43 57 | 
             
            executables: []
         | 
| @@ -56,7 +70,7 @@ homepage: https://github.com/SamSaffron/fast_blank | |
| 56 70 | 
             
            licenses:
         | 
| 57 71 | 
             
            - MIT
         | 
| 58 72 | 
             
            metadata: {}
         | 
| 59 | 
            -
            post_install_message: | 
| 73 | 
            +
            post_install_message:
         | 
| 60 74 | 
             
            rdoc_options: []
         | 
| 61 75 | 
             
            require_paths:
         | 
| 62 76 | 
             
            - lib
         | 
| @@ -71,9 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 71 85 | 
             
                - !ruby/object:Gem::Version
         | 
| 72 86 | 
             
                  version: '0'
         | 
| 73 87 | 
             
            requirements: []
         | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
            signing_key: 
         | 
| 88 | 
            +
            rubygems_version: 3.1.6
         | 
| 89 | 
            +
            signing_key:
         | 
| 77 90 | 
             
            specification_version: 4
         | 
| 78 91 | 
             
            summary: Fast String blank? implementation
         | 
| 79 92 | 
             
            test_files:
         |