All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.barrybecker4.simulation.reactiondiffusion.RDProfiler.scala Maven / Gradle / Ivy

There is a newer version: 1.6.2
Show newest version
/** Copyright by Barry G. Becker, 2000-2017. Licensed under MIT License: http://www.opensource.org/licenses/MIT  */
package com.barrybecker4.simulation.reactiondiffusion

import com.barrybecker4.common.format.FormatUtil
import com.barrybecker4.simulation.common.Profiler


/**
  * Singleton for RD profiling.
  *
  * @author Barry Becker
  */
object RDProfiler {
  private val CONCURRENT_CALCULATION = "concurrent_calculation"
  private var instance: RDProfiler = _

  /**
    * @return singleton instance.
    */
  def getInstance: RDProfiler = {
    if (instance == null) instance = new RDProfiler
    instance
  }
}

class RDProfiler private()

/**
  * Private constructor. Use getInstance instead.
  */
//add(COMMIT_CHANGES, CALCULATION);
  extends Profiler {
  add(RDProfiler.CONCURRENT_CALCULATION, Profiler.CALCULATION)
  private var numFrames = 0

  override def print() {
    super.print()
    val calcTime = getCalcTime
    val renderingTime = getRenderingTime
    printMessage("Number of Frames: " + FormatUtil.formatNumber(numFrames))
    printMessage("Calculation time per frame (sec):" + FormatUtil.formatNumber(calcTime / numFrames))
    printMessage("Rendering time per frame   (sec):" + FormatUtil.formatNumber(renderingTime / numFrames))
    printMessage("FPS: " + FormatUtil.formatNumber((calcTime + renderingTime) / numFrames))
  }

  override def resetAll() {
    super.resetAll()
    numFrames = 0
  }

  def startConcurrentCalculationTime() {
    this.start(RDProfiler.CONCURRENT_CALCULATION)
  }

  def stopConcurrentCalculationTime() {
    this.stop(RDProfiler.CONCURRENT_CALCULATION)
  }

  override def stopRenderingTime() {
    super.stopRenderingTime()
    numFrames += 1
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy