Commit b8d9234d authored by Paul Asmuth's avatar Paul Asmuth
Browse files

benchmark stub

parent 583671f2
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
// FnordMetric Enterprise
//   (c) 2011-2013 Paul Asmuth <paul@paulasmuth.com>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT

package com.fnordmetric.enterprise

object Benchmark {

  def run : Unit = {
    print_title("Metric#sample")
    for (n <- List(1000, 10000, 1000000))
      for (t <- List(1, 2, 4, 8, 16, 32, 64))
      bm_metric(n, t)

  }

  private def bm_metric(samples: Int, threads: Int) : Unit = {
    val metric = new Metric(
      MetricKey("fnord", "sum", 1.toLong))

    val t0 = FnordMetric.now

    for (n <- (1 to samples))
      metric.sample(23)

    val t1 = FnordMetric.now
    print_res(samples + " values, " + threads + " thread(s)", t0, t1)
  }

  // HACK !!! ;)
  private def print_res(title: String, t0: Long, t1: Long) =
    println("  * " + title +
      (("" /: (1 to (30 - title.length)))((m,c) => m + " ")) + " => " +
      (t1-t0) + "ms")

  // HACK !!! ;)
  private def print_title(title: String) =
    println(title + "\n" +
      (("" /: (1 to (title.length)))((m,c) => m + "=")) + "\n")

}
+14 −11
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ object FnordMetric {
      else if ((args(n) == "-h") || (args(n) == "--help"))
        return usage(true)

      else if (args(n) == "--benchmark")
        return Benchmark.run

      else {
        println("error: invalid option: " + args(n) + "\n")
        return usage(false)
+2 −2
Original line number Diff line number Diff line
@@ -38,14 +38,14 @@ class Metric(key: MetricKey) {
    }

    rbuf.push(((time, value)))
    println("RINGBUF", rbuf.tail(10))
    //println("RINGBUF", rbuf.tail(10))
  }

  // tries to persist as much data from the in memory ring buffer to disk
  // as possible but doesnt remove it from the buffer yet
  def flush_rbuf = this.synchronized {
    val flush_range = rbuf.size - rbuf_seek_pos
    println("RBUF_FLUSH", rbuf.tail(flush_range))
    //println("RBUF_FLUSH", rbuf.tail(flush_range))
    rbuf_seek_pos += flush_range
  }

+2 −4
Original line number Diff line number Diff line
@@ -10,14 +10,12 @@ package com.fnordmetric.enterprise
class SumBucket extends AbstractBucket {
  var tmp : Double = 0

  def sample(value: Double) : Unit = {
    tmp += value; println("val: " + tmp) }
  def sample(value: Double) : Unit =
    tmp += value

  def flush : Double = {
    val res = tmp
    tmp = 0.toDouble

    println("flush: " + res)
    res
  }