performance measurements

Each table row shows performance measurements for this Ruby JRuby program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
250,000Failed  996   

Read the ↓ make, command line, and program output logs to see how this program was run.

Read k-nucleotide benchmark to see what this program should do.

 notes

jruby 1.7.11 (1.9.3p392) 2014-02-24 86339bb on Java HotSpot(TM) Server VM 1.8.0-b132 +indy [linux-i386]

 k-nucleotide Ruby JRuby #5 program source code

# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org
#
# contributed by Aaron Tavistock
# optimised && parallelised by Scott Leggett

module MiniParallel
    class Worker
        def initialize(read, write)
            @read, @write = read, write
        end

        def close_pipes
            @read.close
            @write.close
        end

        def work(index)
            Marshal.dump(index, @write)
            Marshal.load(@read)
        end
    end

    def self.map(array, &block)
        work_in_processes(
            array,
            [array.size, core_count].min,
            &block
        )
    end

    def self.core_count
        @@core_count ||= IO.read("/proc/cpuinfo").scan(/^processor/).size
    end

    private

    def self.work_in_processes(array, count, &block)
        index = -1
        results, threads = [], []

        workers = create_workers(array, count, &block)

        workers.each do |worker|
            threads << Thread.new do
              loop do
                Thread.exclusive{ index += 1 }
                break if index >= array.size
                results[index] = worker.work(index)
              end
              worker.close_pipes
            end
        end

        threads.each(&:join)
        Process.waitall

        results
    end

    def self.create_workers(array, count, &block)
        workers = []
        count.times do
            workers << create_worker(array, workers, &block)
        end
        workers
    end

    def self.create_worker(array, started_workers, &block)
        child_read, parent_write = IO.pipe
        parent_read, child_write = IO.pipe

        Process.fork do
            started_workers.each(&:close_pipes)

            parent_write.close
            parent_read.close

            process_incoming_jobs(child_read, child_write, array, &block)

            child_read.close
            child_write.close
        end

        child_read.close
        child_write.close

        Worker.new(parent_read, parent_write)
    end

    def self.process_incoming_jobs(read, write, array, &block)
        until read.eof?
            index = Marshal.load(read)
            Marshal.dump(block.call(array[index]), write)
        end
    end
end

def frequency(seq, keys)
    MiniParallel.map(keys) do |key|
        if key.size == 1
            [seq.count(key), key.upcase]
        else
            index = count = 0
            while index = seq.index(key, index+1)
                count += 1
            end
            [count, key.upcase]
        end
    end
end

def percentage(seq, keys)
    frequency(seq, keys).sort!.reverse!.map! do |value, key|
        "%s %.3f" % [ key, ((value*100).to_f / seq.size) ]
    end
end

def count(seq, keys)
    frequency(seq, keys).map! do |value, key|
        [value, key].join("\t")
    end
end

seq = STDIN.map do |line|
    line.chomp! if line.include?('>TH') .. false
end.compact[1..-1].join

singles = ['a', 't', 'c', 'g']
doubles = ['aa', 'at', 'ac', 'ag', 'ta', 'tt', 'tc', 'tg', 'ca', 'ct', 'cc',
           'cg', 'ga', 'gt', 'gc', 'gg']
chains  = ['ggt', 'ggta', 'ggtatt', 'ggtattttaatt', 'ggtattttaatttatagt']

puts percentage(seq, singles).join("\n"), "\n"
puts percentage(seq, doubles).join("\n"), "\n"
puts count(seq, chains).join("\n")

 make, command-line, and program output logs

Wed, 03 Sep 2014 23:42:08 GMT

MAKE:
mv knucleotide.jruby-5.jruby knucleotide.rb
0.03s to complete and log all make actions

COMMAND LINE:
/usr/local/src/jruby-1.7.11/bin/jruby -Xcompile.invokedynamic=true -J-server -J-Xmn512m -J-Xms2048m -J-Xmx2048m knucleotide.rb 0 < knucleotide-input250000.txt

PROGRAM FAILED 


PROGRAM OUTPUT:

NotImplementedError: fork is not available on this platform
               fork at org/jruby/RubyProcess.java:1054
      create_worker at knucleotide.rb:73
     create_workers at knucleotide.rb:64
              times at org/jruby/RubyFixnum.java:275
     create_workers at knucleotide.rb:63
  work_in_processes at knucleotide.rb:42
                map at knucleotide.rb:25
          frequency at knucleotide.rb:100
         percentage at knucleotide.rb:114
             (root) at knucleotide.rb:134

Revised BSD license

  Home   Conclusions   License   Play