The Computer Language
23.03 Benchmarks Game

reverse-complement Matz's Ruby #3 program

source code

# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# Contributed by Aaron Tavistock

def process_segment(segment)
  (header, _, sequence) = segment.partition("\n")

  sequence.delete!("\n\r >")
  sequence.reverse!
  sequence.tr!(
    'wsatugcyrkmbdhvnATUGCYRKMBDHVN',
    'WSTAACGRYMKVHDBNTAACGRYMKVHDBN'
  )

  results = [">#{header}"]

  idx = 0
  length = sequence.length
  while idx < length
    results << sequence[idx,60]
    idx += 60
  end

  results.join("\n")
end

def forking_worker(segment)
  reader, writer = IO.pipe

  pid = Process.fork do
    begin
      reader.close
      results = process_segment(segment)
      Marshal.dump(results, writer)
    ensure
      writer.close
    end
  end

  writer.close
  begin
    results = Marshal.load(reader)
  ensure
    reader.close
  end
  Process.waitpid(pid)

  results
end

threads = []
$stdin.each_line('>') do |segment|
  next if segment.length < 2

  threads << Thread.new do
      Thread.current[:output] = forking_worker(segment)
  end
end
threads.each(&:join)

threads.each do |thread|
  puts thread[:output]
end
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
ruby 1.8.7 
(2014-01-28
patchlevel 376)
[x86_64-linux]



Thu, 09 Feb 2023 16:16:38 GMT

COMMAND LINE:
/usr/share/rvm/rubies/ruby-1.8.7-head/bin/ruby  revcomp.mri-3.mri 0 < revcomp-input250000.txt

PROGRAM FAILED 


PROGRAM OUTPUT:

revcomp.mri-3.mri:43:in `load': method `getc' called on terminated object (0x5579fc103430) (NotImplementedError)
	from revcomp.mri-3.mri:43:in `join'
	from revcomp.mri-3.mri:43:in `to_proc'
	from revcomp.mri-3.mri:60:in `each'
	from revcomp.mri-3.mri:60