-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// Benchmark.Native.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Neo.SmartContract; | ||
using Neo.VM.Benchmark.OpCode; | ||
|
||
namespace Neo.VM.Benchmark.NativeContract; | ||
|
||
public abstract class Benchmark_Native | ||
{ | ||
private BenchmarkEngine _engine; | ||
Check warning on line 20 in benchmarks/Neo.VM.Benchmarks/NativeContract/Benchmark.Native.cs GitHub Actions / Test (macos-latest)
|
||
|
||
protected abstract SmartContract.Native.NativeContract Native { get; } | ||
protected abstract string Method { get; } | ||
|
||
[ParamsSource(nameof(Params))] | ||
private readonly object[] _args; | ||
protected abstract object[][] Params { get; } | ||
|
||
[IterationSetup] | ||
public void Setup() | ||
{ | ||
|
||
_engine = new BenchmarkEngine(); | ||
_engine.LoadScript(AppCall()); | ||
_engine.ExecuteUntil(VM.OpCode.SYSCALL); | ||
} | ||
|
||
[IterationCleanup] | ||
public void Cleanup() | ||
{ | ||
_engine.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void Bench() | ||
{ | ||
_engine.ExecuteNext(); | ||
} | ||
|
||
protected byte[] AppCall() | ||
{ | ||
var builder = new ScriptBuilder(); | ||
|
||
foreach (var o in _args) | ||
{ | ||
builder.EmitPush(o); | ||
} | ||
|
||
builder.EmitPush(_args.Length); | ||
builder.Emit(VM.OpCode.PACK); | ||
|
||
builder.EmitPush((byte)CallFlags.None); | ||
builder.EmitPush(Method); | ||
builder.EmitPush(Native.Hash); | ||
builder.EmitSysCall(ApplicationEngine.System_Contract_Call); | ||
return builder.ToArray(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// CryptoLib.RIPEMD160.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Neo.SmartContract; | ||
|
||
namespace Neo.VM.Benchmark.NativeContract.CryptoLib; | ||
|
||
public class CryptoLib_RIPEMD160 : Benchmark_Native | ||
{ | ||
|
||
protected override SmartContract.Native.NativeContract Native { get; } | ||
Check warning on line 20 in benchmarks/Neo.VM.Benchmarks/NativeContract/CryptoLib/CryptoLib.RIPEMD160.cs GitHub Actions / Test-Everything
Check warning on line 20 in benchmarks/Neo.VM.Benchmarks/NativeContract/CryptoLib/CryptoLib.RIPEMD160.cs GitHub Actions / Test (windows-latest)
Check warning on line 20 in benchmarks/Neo.VM.Benchmarks/NativeContract/CryptoLib/CryptoLib.RIPEMD160.cs GitHub Actions / Test (macos-latest)
|
||
protected override string Method { get; } | ||
Check warning on line 21 in benchmarks/Neo.VM.Benchmarks/NativeContract/CryptoLib/CryptoLib.RIPEMD160.cs GitHub Actions / Test-Everything
Check warning on line 21 in benchmarks/Neo.VM.Benchmarks/NativeContract/CryptoLib/CryptoLib.RIPEMD160.cs GitHub Actions / Test (windows-latest)
Check warning on line 21 in benchmarks/Neo.VM.Benchmarks/NativeContract/CryptoLib/CryptoLib.RIPEMD160.cs GitHub Actions / Test (macos-latest)
|
||
|
||
protected override object[][] Params | ||
{ | ||
get | ||
{ | ||
var random = new Random(); | ||
return | ||
[ | ||
[RandomBytes(1, random)], | ||
[RandomBytes(10, random)], | ||
[RandomBytes(100, random)], | ||
[RandomBytes(1000, random)], | ||
[RandomBytes(10000, random)], | ||
[RandomBytes(65535, random)], | ||
[RandomBytes(100000, random)], | ||
[RandomBytes(500000, random)], | ||
[RandomBytes(1000000, random)], | ||
[RandomBytes(ushort.MaxValue * 2, random)] | ||
]; | ||
} | ||
} | ||
|
||
private object RandomBytes(int length, Random random) | ||
{ | ||
byte[] buffer = new byte[length]; | ||
random.NextBytes(buffer); | ||
return buffer; | ||
} | ||
|
||
// public static byte[] RIPEMD160(byte[] data) | ||
// { | ||
// return data.RIPEMD160(); | ||
// } | ||
|
||
// methodConvert.CallContractMethod(NativeContract.StdLib.Hash, "itoa", 1, true); | ||
// Loop start. Prepare arguments and call CryptoLib's verifyWithECDsa. | ||
// vrf.EmitPush((byte)NamedCurveHash.secp256k1Keccak256); // push Koblitz curve identifier and Keccak256 hasher. | ||
// vrf.Emit(OpCode.LDLOC0, // load signatures. | ||
// OpCode.LDLOC3, // load sigCnt. | ||
// OpCode.PICKITEM, // pick signature at index sigCnt. | ||
// OpCode.LDLOC1, // load pubs. | ||
// OpCode.LDLOC4, // load pubCnt. | ||
// OpCode.PICKITEM, // pick pub at index pubCnt. | ||
// OpCode.LDLOC2, // load msg. | ||
// OpCode.PUSH4, OpCode.PACK); // pack 4 arguments for 'verifyWithECDsa' call. | ||
// EmitAppCallNoArgs(vrf, CryptoLib.CryptoLib.Hash, "verifyWithECDsa", CallFlags.None); // emit the call to 'verifyWithECDsa' itself. | ||
|
||
|
||
} |