 chalk  = require 'chalk'
 pad    = require 'pad'
 format = require 'comma-number'
+
+SEP = /[,\.]/
 
 class Benchmarks
 

        if change > 0.01 then chalk.green
        else if change < -0.01 then chalk.red
        else chalk.black
      change = color(@format 9, change.toFixed 0) + '%'

    else change = '      N/A '

    label = chalk.bold info.benchmark.label

    console.log """
    #{oldRate} |#{newRate} |#{change} |#{oldTime} |#{newTime} |  #{label}
    """



    if store then @store()


  format: (length, num) -> pad length, @crop length, num, format num

  crop: (length, num, string) ->

    match = SEP.exec string

    if match?

      if match[0] is ','
        string = string[0 ... match.index] + '.' + string[match.index + 1]
        string +=
          switch
            when num < 1e6 then ' G'
            when num < 1e9 then ' M'
            when num < 1e12 then ' B'
            when num < 1e15 then ' T'
            when num < 1e18 then ' P'
            else ' !'

      else string[0..5]

    else string[0...length]


  reportHeader: ->
    padSize = 10
    h1 = chalk.blue pad padSize, 'old ops/s'
    h2 = ' |' + chalk.blue pad padSize, 'new ops/s'
    h3 = ' |' + pad padSize - 1, 'change'
    h4 = ' |' + chalk.magenta pad padSize, ' old secs'
    h5 = ' |' + chalk.magenta pad padSize, ' new secs'
    h6 = ' |' + chalk.bold ' label'
    console.log h1 + h2 + h3 + h4 + h5 + h6
    console.log '----------------------------------------------------------------------------------------------'

  reportResult: (info) ->
    # info = {benchmark, repeat, elapsed, old}
    padSize = 10

    if info.old?
      oldTimeNum = info.old.seconds + (info.old.nanos / 1e9)
