Skip to content

Commit

Permalink
Introduce ArrayRecord (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarao authored Nov 6, 2023
1 parent 71350b5 commit 6a7f9a6
Show file tree
Hide file tree
Showing 33 changed files with 7,980 additions and 381 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package benchmark
package record4s_arrayrecord

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*

@BenchmarkMode(Array(Mode.SingleShotTime))
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
class CompileCreation {
@Param(Array("1", "50", "100", "150", "200", "250"))
var size: Int = 0

var source: String = ""

var compiler: Compiler = null

@Setup(Level.Iteration)
def setup(): Unit = {
compiler = new Compiler

val fields = (1 to size).map(i => s"f${i} = ${i}").mkString(",")
source = s"""
|import com.github.tarao.record4s.ArrayRecord
|object A {
| val r = ArrayRecord(${fields})
|}
|""".stripMargin
}

@Benchmark
def create_fN =
compiler.compile(source)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package benchmark
package record4s_arrayrecord

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*

@BenchmarkMode(Array(Mode.SingleShotTime))
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
class CompileCreationAndAccess {
@Param(Array("1", "50", "100", "150", "200", "250"))
var size: Int = 0

var source: String = ""

var compiler: Compiler = null

@Setup(Level.Iteration)
def setup(): Unit = {
compiler = new Compiler

val fields = (1 to size).map(i => s"f${i} = ${i}").mkString(",")
val access = (1 to size).map(i => s" r.f${i}").mkString("\n")
source = s"""
|import com.github.tarao.record4s.ArrayRecord
|object A {
| val r = ArrayRecord(${fields})
|${access}
|}
|""".stripMargin
}

@Benchmark
def create_fN =
compiler.compile(source)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package benchmark
package record4s_arrayrecord

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*

@BenchmarkMode(Array(Mode.SingleShotTime))
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
class CompileCreationAndAccessRep {
val repetitions = 10

@Param(Array("1", "50", "100", "150", "200", "250"))
var size: Int = 0

var source: String = ""

var compiler: Compiler = null

@Setup(Level.Iteration)
def setup(): Unit = {
compiler = new Compiler

val fields = (1 to size).map(i => s"f${i} = ${i}").mkString(",")
val access = (1 to repetitions).map(_ => s" r.f${size}").mkString("\n")
source = s"""
|import com.github.tarao.record4s.ArrayRecord
|object A {
| val r = ArrayRecord(${fields})
|${access}
|}
|""".stripMargin
}

@Benchmark
def create_fN =
compiler.compile(source)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package benchmark
package record4s_arrayrecord

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*

import com.github.tarao.record4s.ArrayRecord

@BenchmarkMode(Array(Mode.SingleShotTime))
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
class CompileFieldAccess {
@Param(Array("1", "2", "4", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32"))
var index: Int = 0

var source: String = ""

var compiler: Compiler = null

@Setup(Level.Iteration)
def setup(): Unit = {
compiler = new Compiler

source = s"""
|import benchmark.record4s_arrayrecord.CompileFieldAccess.r
|object A {
| r.f${index}
|}
|""".stripMargin
}

@Benchmark
def access_fN =
compiler.compile(source)
}

object CompileFieldAccess {
val r = ArrayRecord(
f1 = 1,
f2 = 2,
f3 = 3,
f4 = 4,
f5 = 5,
f6 = 6,
f7 = 7,
f8 = 8,
f9 = 9,
f10 = 10,
f11 = 11,
f12 = 12,
f13 = 13,
f14 = 14,
f15 = 15,
f16 = 16,
f17 = 17,
f18 = 18,
f19 = 19,
f20 = 20,
f21 = 21,
f22 = 22,
f23 = 23,
f24 = 24,
f25 = 25,
f26 = 26,
f27 = 27,
f28 = 28,
f29 = 29,
f30 = 30,
f31 = 31,
f32 = 32,
)
}
Loading

0 comments on commit 6a7f9a6

Please sign in to comment.