Skip to content

Commit

Permalink
Add method benchmarks (#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
4e6 authored Dec 7, 2021
1 parent 51d1c94 commit 04ac2a2
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.enso.interpreter.bench.benchmarks.semantic;

import java.util.concurrent.TimeUnit;

import org.enso.interpreter.bench.fixtures.semantic.CallableFixtures;
import org.enso.interpreter.bench.fixtures.semantic.NamedDefaultedArgumentFixtures;
import org.enso.interpreter.test.DefaultInterpreterRunner;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;

@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class CallableBenchmarks {
private static final CallableFixtures argumentFixtures =
new CallableFixtures();

private void runOnHundredMillion(DefaultInterpreterRunner.MainMethod main) {
main.mainFunction().value().execute(main.mainConstructor(), argumentFixtures.hundredMillion());
}

@Benchmark
public void benchSumTCOfromCall() {
runOnHundredMillion(argumentFixtures.sumTCOfromCall());
}

@Benchmark
public void benchSumTCOmethodCall() {
runOnHundredMillion(argumentFixtures.sumTCOmethodCall());
}

@Benchmark
public void benchSumTCOmethodCallWithNamedArguments() {
runOnHundredMillion(argumentFixtures.sumTCOmethodCallWithDefaultedArguments());
}

@Benchmark
public void benchSumTCOmethodCallWithDefaultedArguments() {
runOnHundredMillion(argumentFixtures.sumTCOmethodCallWithDefaultedArguments());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.enso.interpreter.bench.fixtures.semantic

import org.enso.interpreter.test.DefaultInterpreterRunner

class CallableFixtures extends DefaultInterpreterRunner {
val hundredMillion: Long = 100000000

val sumTCOfromCallCode =
"""
|from Standard.Builtins import all
|
|type Foo
|
|Foo.from (acc : Number) = current ->
| if current == 0 then acc else @Tail_Call Foo.from (acc + current) (current - 1)
|
|main = sumTo ->
| res = Foo.from 0 sumTo
| res
|""".stripMargin
val sumTCOfromCall = getMain(sumTCOfromCallCode)


val sumTCOmethodCallCode =
"""
|summator = acc -> current ->
| if current == 0 then acc else @Tail_Call here.summator (acc + current) (current - 1)
|
|main = sumTo ->
| res = here.summator 0 sumTo
| res
|""".stripMargin
val sumTCOmethodCall = getMain(sumTCOmethodCallCode)

val sumTCOmethodCallWithNamedArgumentsCode =
"""
|summator = acc -> current ->
| if current == 0 then acc else @Tail_Call here.summator (current = current - 1) (acc = acc + current)
|
|main = sumTo ->
| res = here.summator current=sumTo acc=0
| res
|""".stripMargin
val sumTCOmethodCallWithNamedArguments =
getMain(sumTCOmethodCallWithNamedArgumentsCode)

val sumTCOmethodCallWithDefaultedArgumentsCode =
"""
|summator = (acc = 0) -> current ->
| if current == 0 then acc else @Tail_Call here.summator (current = current - 1) (acc = acc + current)
|
|main = sumTo ->
| res = here.summator current=sumTo
| res
|""".stripMargin
val sumTCOmethodCallWithDefaultedArguments =
getMain(sumTCOmethodCallWithDefaultedArgumentsCode)

}

0 comments on commit 04ac2a2

Please sign in to comment.