Skip to content

Commit

Permalink
use best practice @State in example
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb committed Dec 12, 2024
1 parent 639e121 commit 01301b5
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package org.broadinstitute.dsde.firecloud.utils

import org.openjdk.jmh.annotations.Benchmark
import org.broadinstitute.dsde.firecloud.utils.TsvFormatterBenchmark.Inputs
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import org.openjdk.jmh.infra.Blackhole

object TsvFormatterBenchmark {

@State(Scope.Thread)
class Inputs {
val inputNoTab = "foo"
val inputWithTab = "foo\tbar"
}

}

class TsvFormatterBenchmark {

@Benchmark
def tsvSafeStringNoTab(blackHole: Blackhole): String = {
val result = TSVFormatter.tsvSafeString("foo")
def tsvSafeStringNoTab(blackHole: Blackhole, inputs: Inputs): String = {
val result = TSVFormatter.tsvSafeString(inputs.inputNoTab)
blackHole.consume(result)
result
}

@Benchmark
def tsvSafeStringWithTab(blackHole: Blackhole): String = {
val result = TSVFormatter.tsvSafeString("foo\tbar")
def tsvSafeStringWithTab(blackHole: Blackhole, inputs: Inputs): String = {
val result = TSVFormatter.tsvSafeString(inputs.inputWithTab)
blackHole.consume(result)
result
}
Expand Down

0 comments on commit 01301b5

Please sign in to comment.