Commit a991699
Changed files (3)
bin/perf.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+FILENAME=$(date +%s)
+
+mkdir -p tmp/graphs
+
+gnuplot << EOF
+ set title 'time analysis'
+ set xlabel "Time (seconds)"
+ set ylabel "Input size (n)"
+ set grid
+ set term png
+ set output "tmp/graphs/$FILENAME.png"
+ set datafile separator ","
+ plot 'tmp/input.csv'
+EOF
+
+echo "tmp/graphs/$FILENAME.png"
spec/triplet_sum_spec.rb
@@ -100,7 +100,7 @@ describe "triplet sum" do
end
#def triplet_sum(target, items)
- #items.combination(3).to_a.any? { |x| x.reduce(:+) == target }
+ #items.combination(3).to_a.any? { |x| x.reduce(:+) == target }
#end
it do
@@ -157,15 +157,20 @@ describe "triplet sum" do
end
end
- xit 'plots the time for each' do
- puts "\"n\",\"time (seconds)\""
- 10.times do |n|
- items = Array.new((n + 1) * 1_000) { rand(100) }
- start_time = Time.now
- triplet_sum(rand(100), items)
- end_time = Time.now
- #puts "#{items.size} items: #{(end_time - start_time) * 1_000} seconds"
- puts "\"#{items.size}\",\"#{(end_time - start_time) * 1_000}\""
+ it 'plots the time for each' do
+ filename = "tmp/input.csv"
+ File.unlink(filename) if File.exist?(filename)
+ File.open(filename, "w") do |file|
+ 500.times do |n|
+ total = (n + 1) * 1_000
+ items = Array.new(total) { rand(total) }
+ target = rand(100)
+ start_time = Time.now
+ triplet_sum(target, items)
+ end_time = Time.now
+ puts "#{(end_time - start_time) * 1_000},#{items.size}"
+ file.write("#{(end_time - start_time) * 1_000},#{items.size}\n")
+ end
end
end
end
.gitignore
@@ -1,1 +1,2 @@
*.byebug_history
+tmp