forked from wavesplatform/Waves
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SC-792 Rebenchmark, add function families and optimize (wavesplatform…
- Loading branch information
Showing
38 changed files
with
1,205 additions
and
366 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressToStringBenchmark.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,46 @@ | ||
package com.wavesplatform.lang.v1 | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import com.wavesplatform.account.{Address, PublicKey} | ||
import com.wavesplatform.common.state.ByteStr | ||
import com.wavesplatform.crypto.Curve25519 | ||
import com.wavesplatform.lang.v1.FunctionHeader.Native | ||
import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BYTESTR, CaseObj, FUNCTION_CALL} | ||
import com.wavesplatform.lang.v1.evaluator.FunctionIds | ||
import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.Types | ||
import org.openjdk.jmh.annotations._ | ||
import com.wavesplatform.common.utils._ | ||
import com.wavesplatform.lang.v1.AddressToStringBenchmark.AddressToString | ||
import org.openjdk.jmh.infra.Blackhole | ||
|
||
import scala.util.Random | ||
import com.wavesplatform.lang.v1.PureFunctionsRebenchmark.evalV5 | ||
|
||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Threads(1) | ||
@Fork(1) | ||
@Warmup(iterations = 10, time = 1) | ||
@Measurement(iterations = 10, time = 1) | ||
class AddressToStringBenchmark { | ||
@Benchmark | ||
def addressToString(bh: Blackhole, st: AddressToString): Unit = | ||
bh.consume(evalV5(st.expr)) | ||
} | ||
|
||
object AddressToStringBenchmark { | ||
@State(Scope.Benchmark) | ||
class AddressToString { | ||
val publicKey = new Array[Byte](Curve25519.KeyLength) | ||
Random.nextBytes(publicKey) | ||
|
||
val address = Address.fromPublicKey(PublicKey(publicKey)).bytes | ||
|
||
val expr = | ||
FUNCTION_CALL( | ||
Native(FunctionIds.ADDRESSTOSTRING), | ||
List(CaseObj(Types.addressType, Map("bytes" -> CONST_BYTESTR(ByteStr(address)).explicitGet()))) | ||
) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
benchmark/src/test/scala/com/wavesplatform/lang/v1/BigIntToStringBenchmark.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,37 @@ | ||
package com.wavesplatform.lang.v1 | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import com.wavesplatform.lang.Common | ||
import com.wavesplatform.lang.directives.DirectiveSet | ||
import com.wavesplatform.lang.directives.values.{Account, Expression, V5} | ||
import com.wavesplatform.lang.utils.lazyContexts | ||
import com.wavesplatform.lang.v1.FunctionHeader.Native | ||
import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BIGINT, FUNCTION_CALL} | ||
import com.wavesplatform.lang.v1.evaluator.EvaluatorV2 | ||
import com.wavesplatform.lang.v1.evaluator.FunctionIds.BIGINT_TO_STRING | ||
import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext | ||
import org.openjdk.jmh.annotations.{State, _} | ||
import org.openjdk.jmh.infra.Blackhole | ||
|
||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Threads(1) | ||
@Fork(1) | ||
@Warmup(iterations = 10, time = 1) | ||
@Measurement(iterations = 10, time = 1) | ||
class BigIntToStringBenchmark { | ||
@Benchmark | ||
def toString(bh: Blackhole, s: BigIntToStringSt): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr, V5)) | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
class BigIntToStringSt { | ||
val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) | ||
val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) | ||
|
||
val expr = FUNCTION_CALL( | ||
Native(BIGINT_TO_STRING), | ||
List(CONST_BIGINT(PureContext.BigIntMin)) | ||
) | ||
} |
83 changes: 83 additions & 0 deletions
83
benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionBigIntBenchmark.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,83 @@ | ||
package com.wavesplatform.lang.v1 | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import com.wavesplatform.lang.Common | ||
import com.wavesplatform.lang.directives.DirectiveSet | ||
import com.wavesplatform.lang.directives.values.{Account, Expression, V5} | ||
import com.wavesplatform.lang.utils.lazyContexts | ||
import com.wavesplatform.lang.v1.FunctionHeader.Native | ||
import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BIGINT, FUNCTION_CALL} | ||
import com.wavesplatform.lang.v1.evaluator.EvaluatorV2 | ||
import com.wavesplatform.lang.v1.evaluator.FunctionIds.{FRACTION_BIGINT, FRACTION_BIGINT_ROUNDS} | ||
import com.wavesplatform.lang.v1.evaluator.ctx.impl.{PureContext, Rounding} | ||
import org.openjdk.jmh.annotations.{State, _} | ||
import org.openjdk.jmh.infra.Blackhole | ||
|
||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Threads(1) | ||
@Fork(1) | ||
@Warmup(iterations = 10, time = 1) | ||
@Measurement(iterations = 10, time = 1) | ||
class FractionBigIntBenchmark { | ||
@Benchmark | ||
def fraction1(bh: Blackhole, s: FractionBigIntSt): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1, V5)) | ||
|
||
@Benchmark | ||
def fraction2(bh: Blackhole, s: FractionBigIntSt): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2, V5)) | ||
|
||
@Benchmark | ||
def fraction3(bh: Blackhole, s: FractionBigIntSt): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3, V5)) | ||
|
||
@Benchmark | ||
def fraction1Round(bh: Blackhole, s: FractionBigIntSt): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1Round, V5)) | ||
|
||
@Benchmark | ||
def fraction2Round(bh: Blackhole, s: FractionBigIntSt): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2Round, V5)) | ||
|
||
@Benchmark | ||
def fraction3Round(bh: Blackhole, s: FractionBigIntSt): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3Round, V5)) | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
class FractionBigIntSt { | ||
val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) | ||
val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) | ||
|
||
val max = CONST_BIGINT(PureContext.BigIntMax) | ||
val halfMax = CONST_BIGINT(PureContext.BigIntMax / 2) | ||
val min = CONST_BIGINT(PureContext.BigIntMin) | ||
val maxSqrt = CONST_BIGINT(BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819968")) | ||
val three = CONST_BIGINT(3) | ||
|
||
val expr1 = FUNCTION_CALL( | ||
Native(FRACTION_BIGINT), | ||
List(halfMax, three, three) | ||
) | ||
|
||
val expr2 = FUNCTION_CALL( | ||
Native(FRACTION_BIGINT), | ||
List(max, min, min) | ||
) | ||
|
||
val expr3 = FUNCTION_CALL( | ||
Native(FRACTION_BIGINT), | ||
List(maxSqrt, maxSqrt, maxSqrt) | ||
) | ||
|
||
val expr1Round = FUNCTION_CALL( | ||
Native(FRACTION_BIGINT_ROUNDS), | ||
List(halfMax, three, three, Rounding.HalfEven.value) | ||
) | ||
|
||
val expr2Round = FUNCTION_CALL( | ||
Native(FRACTION_BIGINT_ROUNDS), | ||
List(max, min, min, Rounding.HalfEven.value) | ||
) | ||
|
||
val expr3Round = FUNCTION_CALL( | ||
Native(FRACTION_BIGINT_ROUNDS), | ||
List(maxSqrt, maxSqrt, maxSqrt, Rounding.HalfEven.value) | ||
) | ||
} |
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
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
Oops, something went wrong.