Class: Bench::Commands::Report

Inherits:
Command
  • Object
show all
Defined in:
lib/bench9000/commands/report.rb

Constant Summary collapse

REPORT_DIR =

TODO (pitr 03-Dec-2015): use data file name instead of report.html

"#{File.dirname(__FILE__)}/../report"

Instance Method Summary collapse

Methods inherited from Command

#before, #benchmark_complete, #result

Instance Method Details

#after(options, measurements) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bench9000/commands/report.rb', line 18

def after(options, measurements)
  report = read("report.html")

  replacements = {
    '<script src="jquery.js"></script>' =>
      "<script>#{read('jquery.js')}</script>",

    '<script src="bootstrap.js"></script>' =>
      "<script>#{read('bootstrap.js')}</script>",

    '<script src="chart.js"></script>' =>
      "<script>#{read('chart.js')}</script>",

    '<script src="data.js"></script>' =>
      "<script>bench_data = #{JSONFormatter.format(options, measurements)};</script>",

    '<script src="report.js"></script>' =>
      "<script>#{read('report.js')}</script>",

    '<link rel="stylesheet" type="text/css" href="bootstrap.css">' =>
      "<style>#{read('bootstrap.css')}</style>",

    '<link rel="stylesheet" type="text/css" href="bootstrap-theme.css">' =>
      "<style>#{read('bootstrap-theme.css')}</style>"
  }

  replacements.each do |find, replace|
    report[find] = replace
  end

  if options.flags.has_key? "--baseline"
    report["var speedup_reference_implementation = bench_data.implementations[0];"] =
      "var speedup_reference_implementation = \"#{options.flags['--baseline']}\";"
  end

  report["<!-- notes -->"] = "<p>Report generated at #{Time.now}</p><!-- notes -->"

  if options.flags.has_key? "--notes"
    report["<!-- notes -->"] = File.open(options.flags["--notes"]).read
  end

  File.open("report.html", "w").write(report)

  puts "Total benchmarking time: #{(measurements.total_time/60).round}m"
end

#read(file) ⇒ Object



64
65
66
# File 'lib/bench9000/commands/report.rb', line 64

def read(file)
  File.open("#{REPORT_DIR}/#{file}", "r").read()
end