summaryrefslogtreecommitdiff
path: root/benchmark/so_reverse_complement.yml
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-08 14:38:05 (GMT)
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-08 14:38:05 (GMT)
commit3293322a39f9c9de11c54f9e9e78c55061ac2ce9 (patch)
tree7fb4371a89ef65beae9c264610b1aa996c178ad5 /benchmark/so_reverse_complement.yml
parent1f4541cb98db06c17bfc902dc61a72ee955887d3 (diff)
benchmark: introduce benchmark_driver.gem
Makefile.in: Clone benchmark-driver repository in benchmark/benchmark-driver `make update-benchmark-driver`, like simplecov. win32/Makefile.sub: Roughly do the same thing. .gitignore: Ignore the cloned repository. common.mk: Trigger `make update-benchmark-driver` to run `make benchmark` and adjust arguments for benchmark_driver.gem. benchmark/require.yml: renamed from benchmark/bm_require.rb, benchmark/prepare_require.rb benchmark/require_thread.yml: renamed from benchmark/bm_require_thread.rb, benchmark/prepare_require_thread.rb benchmark/so_count_words.yml: renamed from benchmark/bm_so_count_words.rb, benchmark/prepare_so_count_words.rb, benchmark/wc.input.base benchmark/so_k_nucleotide.yml: renamed from benchmark/bm_so_k_nucleotide.rb, benchmark/prepare_so_k_nucleotide.rb, benchmark/make_fasta_output.rb benchmark/so_reverse_complement.yml: renamed from benchmark/bm_so_reverse_complement.rb, benchmark/prepare_so_reverse_complement.rb, benchmark/make_fasta_output.rb I'm sorry but I made some duplications between benchmark/require.yml and benchmark/require_thread.yml, and between benchmark/so_k_nucleotide.yml and benchmark/so_reverse_complement.yml. If you're not comfortable with it, please combine these YAMLs to share the same prelude. One YAML file can have multiple benchmark definitions sharing prelude. benchmark/driver.rb: Replace its core feature with benchmark_driver.gem. Some old features are gone for now, but I'll add them again later. [Misc #14902] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'benchmark/so_reverse_complement.yml')
-rw-r--r--benchmark/so_reverse_complement.yml137
1 files changed, 137 insertions, 0 deletions
diff --git a/benchmark/so_reverse_complement.yml b/benchmark/so_reverse_complement.yml
new file mode 100644
index 0000000..de05eed
--- /dev/null
+++ b/benchmark/so_reverse_complement.yml
@@ -0,0 +1,137 @@
+prelude: |
+ bm_so_fasta = <<'EOS'
+ # The Computer Language Shootout
+ # http://shootout.alioth.debian.org/
+ # Contributed by Sokolov Yura
+
+ $last = 42.0
+ def gen_random(max, im=139968, ia=3877, ic=29573)
+ (max * ($last = ($last * ia + ic) % im)) / im
+ end
+
+ alu =
+ "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"
+
+ iub = [
+ ["a", 0.27],
+ ["c", 0.12],
+ ["g", 0.12],
+ ["t", 0.27],
+
+ ["B", 0.02],
+ ["D", 0.02],
+ ["H", 0.02],
+ ["K", 0.02],
+ ["M", 0.02],
+ ["N", 0.02],
+ ["R", 0.02],
+ ["S", 0.02],
+ ["V", 0.02],
+ ["W", 0.02],
+ ["Y", 0.02],
+ ]
+ homosapiens = [
+ ["a", 0.3029549426680],
+ ["c", 0.1979883004921],
+ ["g", 0.1975473066391],
+ ["t", 0.3015094502008],
+ ]
+
+ def make_repeat_fasta(id, desc, src, n)
+ puts ">#{id} #{desc}"
+ v = nil
+ width = 60
+ l = src.length
+ s = src * ((n / l) + 1)
+ s.slice!(n, l)
+ puts(s.scan(/.{1,#{width}}/).join("\n"))
+ end
+
+ def make_random_fasta(id, desc, table, n)
+ puts ">#{id} #{desc}"
+ rand, v = nil,nil
+ width = 60
+ chunk = 1 * width
+ prob = 0.0
+ table.each{|v| v[1]= (prob += v[1])}
+ for i in 1..(n/width)
+ puts((1..width).collect{
+ rand = gen_random(1.0)
+ table.find{|v| v[1]>rand}[0]
+ }.join)
+ end
+ if n%width != 0
+ puts((1..(n%width)).collect{
+ rand = gen_random(1.0)
+ table.find{|v| v[1]>rand}[0]
+ }.join)
+ end
+ end
+
+
+ n = (ARGV[0] or 250_000).to_i
+
+ make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
+ make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
+ make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)
+ EOS
+benchmark:
+ - name: so_reverse_complement
+ prelude: |
+ script = File.join(File.dirname($0), 'bm_so_fasta.rb')
+ File.write(script, bm_so_fasta)
+
+ def prepare_fasta_output n
+ filebase = File.join(File.dirname($0), 'fasta.output')
+ script = File.join(File.dirname($0), 'bm_so_fasta.rb')
+ file = "#{filebase}.#{n}"
+
+ unless FileTest.exist?(file)
+ STDERR.puts "preparing #{file}"
+
+ open(file, 'w'){|f|
+ ARGV[0] = n
+ $stdout = f
+ load script
+ $stdout = STDOUT
+ }
+ end
+ end
+ prepare_fasta_output(2_500_000)
+ script: |
+ # The Great Computer Language Shootout
+ # http://shootout.alioth.debian.org/
+ #
+ # Contributed by Peter Bjarke Olsen
+ # Modified by Doug King
+
+ seq=Array.new
+
+ def revcomp(seq)
+ seq.reverse!.tr!('wsatugcyrkmbdhvnATUGCYRKMBDHVN','WSTAACGRYMKVHDBNTAACGRYMKVHDBN')
+ stringlen=seq.length
+ 0.step(stringlen-1,60) {|x| print seq.slice(x,60) , "\n"}
+ end
+
+ input = open(File.join(File.dirname($0), 'fasta.output.2500000'), 'rb')
+
+ while input.gets
+ if $_ =~ />/
+ if seq.length != 0
+ revcomp(seq.join)
+ seq=Array.new
+ end
+ puts $_
+ else
+ $_.sub(/\n/,'')
+ seq.push $_
+ end
+ end
+ revcomp(seq.join)
+ loop_count: 1