Sha256: be71e382742bc676e7f442090994d7fbb85aef019e28a024165e9e9a188048d7

Contents?: true

Size: 779 Bytes

Versions: 21

Compression:

Stored size: 779 Bytes

Contents

require "disposable/twin"
require 'reform'
require 'ostruct'
require 'benchmark'

class BandForm < Reform::Form
  property :name, validates: {presence: true}

  collection :songs do
    property :title, validates: {presence: true}
  end
end

songs = 50.times.collect { OpenStruct.new(title: "Be Stag") }
band = OpenStruct.new(name: "Teenage Bottlerock", songs: songs)

songs_params = 50.times.collect { {title: "Commando"} }

time = Benchmark.measure do
  100.times.each do
    form = BandForm.new(band)
    form.validate("name" => "Ramones", "songs" => songs_params)
    form.save
  end
end

puts time

# with old Fields.new(to_hash)
#   4.200000
# 20%
# with setup and new(fields).from_object(twin) instead of Fields.new(to_hash)
#   3.680000   0.000000   3.680000 (  3.685796)

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
disposable-0.2.3 test/twin/benchmarking.rb
disposable-0.2.2 test/twin/benchmarking.rb
disposable-0.2.1 test/twin/benchmarking.rb
disposable-0.1.15 test/twin/benchmarking.rb
disposable-0.2.0 test/twin/benchmarking.rb
disposable-0.2.0.rc2 test/twin/benchmarking.rb
disposable-0.2.0.rc1 test/twin/benchmarking.rb
disposable-0.1.14 test/twin/benchmarking.rb
disposable-0.1.13 test/twin/benchmarking.rb
disposable-0.1.12 test/twin/benchmarking.rb
disposable-0.1.11 test/twin/benchmarking.rb
disposable-0.1.9 test/twin/benchmarking.rb
disposable-0.1.8 test/twin/benchmarking.rb
disposable-0.1.7 test/twin/benchmarking.rb
disposable-0.1.6 test/twin/benchmarking.rb
disposable-0.1.5 test/twin/benchmarking.rb
disposable-0.1.4 test/twin/benchmarking.rb
disposable-0.1.3 test/twin/benchmarking.rb
disposable-0.1.2 test/twin/benchmarking.rb
disposable-0.1.1 test/twin/benchmarking.rb