Skip to content

Commit

Permalink
useful benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb committed Dec 17, 2024
1 parent ed0261d commit 7195f87
Showing 1 changed file with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
package org.broadinstitute.dsde.firecloud.utils

import org.broadinstitute.dsde.firecloud.utils.TsvFormatterBenchmark.Inputs
import org.broadinstitute.dsde.firecloud.model.{FlexibleModelSchema, ModelSchema}
import org.broadinstitute.dsde.firecloud.utils.TsvFormatterBenchmark.EntityData
import org.broadinstitute.dsde.rawls.model._
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 EntityData {
val entityType: String = "sample"

val model: ModelSchema = FlexibleModelSchema

val headers: IndexedSeq[String] = IndexedSeq("sample_id", "col1", "col2", "fourth", "last")

val entities: Seq[Entity] = Seq(
Entity(
"1",
entityType,
Map(
AttributeName.withDefaultNS("col1") -> AttributeString("foo"),
AttributeName.withDefaultNS("col2") -> AttributeBoolean(true),
AttributeName.withDefaultNS("fourth") -> AttributeNumber(42),
AttributeName.withDefaultNS("last") -> AttributeString("gs://some-bucket/somefile.ext")
)
),
Entity(
"0005",
entityType,
Map(
AttributeName.withDefaultNS("col1") -> AttributeString("bar"),
AttributeName.withDefaultNS("col2") -> AttributeBoolean(false),
AttributeName.withDefaultNS("fourth") -> AttributeNumber(98.765),
AttributeName.withDefaultNS("last") -> AttributeEntityReference("targetType", "targetName")
)
),
Entity(
"789",
entityType,
Map(
AttributeName.withDefaultNS("col1") -> AttributeString("baz\tqux"),
AttributeName.withDefaultNS("col2") -> AttributeBoolean(true),
AttributeName.withDefaultNS("fourth") -> AttributeNumber(-123.45),
AttributeName.withDefaultNS("last") -> AttributeValueList(
Seq(AttributeString("gs://some-bucket/somefile1.ext"),
AttributeString("gs://some-bucket/somefile2.ext"),
AttributeString("gs://some-bucket/somefile3.ext")
)
)
)
)
)
}

}

class TsvFormatterBenchmark {

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

@Benchmark
def tsvSafeStringWithTab(blackHole: Blackhole, inputs: Inputs): String = {
val result = TSVFormatter.tsvSafeString(inputs.inputWithTab)
def makeEntityRows(blackHole: Blackhole, entityData: EntityData): IndexedSeq[IndexedSeq[String]] = {
val result =
TSVFormatter.makeEntityRows(entityData.entityType, entityData.entities, entityData.headers)(entityData.model)
blackHole.consume(result)
result
}
Expand Down

0 comments on commit 7195f87

Please sign in to comment.