Skip to content

Commit

Permalink
use high resolution monotonic timer to measure FPS
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Sep 20, 2021
1 parent 4f63b39 commit cdd440f
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class QRCodeImageAnalyzer(private val mActivity: QRScannerActivity, private val
private val TAG = "QRCodeImageAnalyzer"

private var frameCounter = 0
private var lastFpsTimestamp = System.currentTimeMillis()
private var lastFpsTimestamp = System.nanoTime()

private val reader = MultiFormatReader()
private var imageData = ByteArray(0)
Expand Down Expand Up @@ -71,9 +71,9 @@ class QRCodeImageAnalyzer(private val mActivity: QRScannerActivity, private val
val frameCount = 10
if (++frameCounter % frameCount == 0) {
frameCounter = 0
val now = System.currentTimeMillis()
val now = System.nanoTime()
val delta = now - lastFpsTimestamp
val fps = 1000 * frameCount.toFloat() / delta
val fps = 1_000_000_000 * frameCount.toFloat() / delta
Log.d(TAG, "Analysis FPS: ${"%.02f".format(fps)}")
lastFpsTimestamp = now
}
Expand Down

0 comments on commit cdd440f

Please sign in to comment.