Sha256: ab9b14f07a90de6569905ec7b6cf1bad2d2a9bd020a301f81264f34295d68b2c

Contents?: true

Size: 660 Bytes

Versions: 4

Compression:

Stored size: 660 Bytes

Contents

window.benchmark = (method, iterations, args, context) ->
  time = 0
  timer = (action) ->
    d = +(new Date)
    if time < 1 or action is "start"
      time = d
      0
    else if action is "stop"
      t = d - time
      time = 0
      t
    else
      d - time

  result = []
  i = 0
  timer "start"
  context = window if !context
  while i < iterations
    result.push method.apply(context, args)
    i++
  execTime = timer("stop")
  if typeof console is "object"
    console.log "Mean execution time was: ", execTime / iterations
    console.log "Sum execution time was: ", execTime
    console.log "Result of the method call was:", result[0]
  execTime

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
webmate-client-0.1.3 vendor/assets/javascripts/webmate/libs/benchmark.coffee
webmate-client-0.1.1 vendor/assets/javascripts/webmate/libs/benchmark.coffee
webmate-0.1.1 vendor/assets/javascripts/webmate/libs/benchmark.coffee
webmate-0.1.0 vendor/assets/javascripts/webmate/libs/benchmark.coffee