mirror of
https://github.com/enso-org/enso.git
synced 2024-12-24 05:12:31 +03:00
Add method benchmarks (#3180)
This commit is contained in:
parent
51d1c941f5
commit
04ac2a2009
@ -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());
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user