Sha256: 8469872eeb9f064369eaca8ff499307b7eba08be8f25146fa664682d7adb45e4

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

require 'bundler/setup'
require 'lenjador/preprocessors/whitelist'
require 'benchmark/ips'

pointers = %w[
  /scalar
  /flat_hash/~
  /nested_hash/~/deep_hash/~
  /flat_array/~
  /nested_array/~/deep_array/~
]

%w[prune mask].each do |action|
  preprocessor = Lenjador::Preprocessors::Whitelist.new(pointers: pointers, action: action)

  Benchmark.ips do |x|
    x.config(time: 5, warmup: 2)

    x.report("Scalar value whitelisting (action=#{action})") do
      preprocessor.process(scalar: 'value', bad_scalar: 'value', hash: {})
    end

    x.report("Flat hash whitelisting (action=#{action})") do
      preprocessor.process(flat_hash: {scalar: 'value', array: [1, 2], hash: {}})
    end

    x.report("Nested hash whitelisting (action=#{action})") do
      preprocessor.process(
        nested_hash: {
          next_level_hash: {
            deep_hash: {scalar: 'value', array: [1, 2]}
          },
          next_level_hash2: {
            deep_hash: {scalar: 'value', array: [1, 2]}
          },
          next_level_hash3: {
            deep_hash: {scalar: 'value', array: [1, 2]}
          }
        }
      )
    end

    x.report("Flat array whitelisting (action=#{action})") do
      preprocessor.process(
        nested_array: [
          {deep_array: [1, 2, 3]},
          {deep_array: [1, 2, 3]},
          {deep_array: [1, 2, 3]}
        ]
      )
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lenjador-2.3.1 benchmark/whitelisting.rb
lenjador-2.3.0 benchmark/whitelisting.rb
lenjador-2.2.2 benchmark/whitelisting.rb
lenjador-2.2.1 benchmark/whitelisting.rb
lenjador-2.2.0 benchmark/whitelisting.rb
lenjador-2.1.0 benchmark/whitelisting.rb
lenjador-2.0.1 benchmark/whitelisting.rb
lenjador-2.0.0 benchmark/whitelisting.rb
lenjador-1.4.0 benchmark/whitelisting.rb
lenjador-1.3.0 benchmark/whitelisting.rb