Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the loop for parsing Integer string #792

Merged
merged 1 commit into from
Jul 23, 2022

Commits on Jul 23, 2022

  1. Simplify the loop for parsing Integer string

    There are several branches in the loop that parse Integer string.
    In order to speed up parsing, this patch will move unwanted branches out of the loop.
    
    −       | before | after  | result
    --       | --     | --     | --
    integer  | 4.860M | 5.088M | 1.045x
    float    | 4.845M | 5.084M | 1.049x
    
    ### Environment
    - Linux
      - Manjaro Linux x86_64
      - Kernel: 5.18.12-3-MANJARO
      - AMD Ryzen 7 5700G
      - gcc version 12.1.0
      - Ruby 3.1.2
    
    ### Before
    ```
    Warming up --------------------------------------
         Oj.load integer   488.037k i/100ms
           Oj.load float   485.863k i/100ms
    Calculating -------------------------------------
         Oj.load integer      4.860M (± 0.1%) i/s -     48.804M in  10.042684s
           Oj.load float      4.845M (± 0.3%) i/s -     48.586M in  10.028592s
    ```
    
    ### After
    ```
    Warming up --------------------------------------
         Oj.load integer   508.044k i/100ms
           Oj.load float   508.281k i/100ms
    Calculating -------------------------------------
         Oj.load integer      5.088M (± 0.2%) i/s -     51.312M in  10.085310s
           Oj.load float      5.084M (± 0.2%) i/s -     51.336M in  10.098332s
    ```
    
    ### Test code
    ```ruby
    require 'benchmark/ips'
    require 'oj'
    
    Benchmark.ips do |x|
      x.warmup = 3
      x.time = 10
    
      json_integer = Oj.dump(2 ** 30)
      x.report('Oj.load integer') do |times|
        i = 0
        while i < times
          Oj.load(json_integer)
          i += 1
        end
      end
    
      json_float = Oj.dump(1234.123456789)
      x.report('Oj.load float') do |times|
        i = 0
        while i < times
          Oj.load(json_integer)
          i += 1
        end
      end
    end
    ```
    Watson1978 committed Jul 23, 2022
    Configuration menu
    Copy the full SHA
    cf9544b View commit details
    Browse the repository at this point in the history