Created
August 10, 2018 22:37
-
-
Save billdueber/76b455bbb98c3564aef37e7f2f058911 to your computer and use it in GitHub Desktop.
Very dirty benchmark looking at a simple threaded marc-binary reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'marc' | |
require 'benchmark' | |
require 'concurrent' | |
require 'concurrent-edge' | |
module MARC | |
class ThreadedReader < Reader | |
def each | |
records = Concurrent::Channel.new(capacity: 20) | |
Concurrent::Channel.go do | |
@handle.each_line(END_OF_RECORD) do |raw| | |
records << raw | |
end | |
records << :done | |
end | |
loop do | |
rawrec = ~records | |
break if rawrec == :done | |
yield MARC::Reader.decode(rawrec, @encoding_options.merge(:forgiving => true)) | |
end | |
end | |
end | |
end | |
filename = '100_000.marc' | |
puts RUBY_DESCRIPTION | |
benchmark_routine = if defined? JRUBY_VERSION | |
:bmbm | |
else | |
:bm | |
end | |
Benchmark.send(benchmark_routine) do |x| | |
x.report('threaded') do | |
threaded_reader = MARC::ThreadedReader.new(filename) | |
title_length = 0 | |
threaded_reader.each do |rec| | |
title_length += rec['245'].value.size | |
end | |
end | |
x.report('standard') do | |
standard_reader = MARC::Reader.new(filename) | |
title_length = 0 | |
standard_reader.each do |rec| | |
title_length += rec['245'].value.size | |
end | |
end | |
end | |
############ TOP LINE RESULTS ######################## | |
# Average of two runs, more or less | |
# | |
# mri 2.5 standard 35s | |
# threaded 26s (71%) | |
# | |
# jruby 9.2 standard 20s | |
# threaded 15s (75%) | |
# | |
# | |
########### Jruby run 2 ############################## | |
# jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 Java HotSpot(TM) 64-Bit Server VM 25.112-b16 on 1.8.0_112-b16 +jit [darwin-x86_64] | |
# Rehearsal -------------------------------------------- | |
# threaded 38.580000 1.290000 39.870000 ( 17.196348) | |
# standard 23.340000 0.410000 23.750000 ( 20.964611) | |
# ---------------------------------- total: 63.620000sec | |
# | |
# user system total real | |
# threaded 29.660000 0.920000 30.580000 ( 15.218190) | |
# standard 19.970000 0.350000 20.320000 ( 20.212276) | |
########### Jruby run 2 ############################## | |
# Rehearsal -------------------------------------------- | |
# threaded 43.480000 1.340000 44.820000 ( 18.160294) | |
# standard 22.940000 0.420000 23.360000 ( 20.704573) | |
# ---------------------------------- total: 68.180000sec | |
# | |
# user system total real | |
# threaded 28.500000 0.930000 29.430000 ( 14.552481) | |
# standard 19.890000 0.370000 20.260000 ( 20.116606) | |
# | |
########### mri run 1 ############################## | |
# ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16] | |
# user system total real | |
# threaded 25.734546 0.450187 26.184733 ( 25.966172) | |
# standard 34.499493 0.393839 34.893332 ( 34.939078) | |
# ######### mri run 2 ############################## | |
# user system total real | |
# threaded 25.136515 0.625168 25.761683 ( 25.734390) | |
# standard 34.278163 0.465162 34.743325 ( 34.888772) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment