-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...ime/src/bench/java/org/enso/interpreter/bench/benchmarks/semantic/CallableBenchmarks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ntime/src/bench/scala/org/enso/interpreter/bench/fixtures/semantic/CallableFixtures.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |