Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// Benchmarks.cs file belongs to the neo project and is free
// Benchmarks.POC.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
Expand All @@ -9,19 +9,21 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using BenchmarkDotNet.Attributes;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.VM;
using System.Diagnostics;

namespace Neo;
namespace Neo.Benchmark;

static class Benchmarks
public class Benchmarks_PoCs
{
private static readonly ProtocolSettings protocol = ProtocolSettings.Load("config.json");
private static readonly NeoSystem system = new(protocol, (string)null);

public static void NeoIssue2725()
[Benchmark]
public void NeoIssue2725()
{
// https://github.com/neo-project/neo/issues/2725
// L00: INITSSLOT 1
Expand Down Expand Up @@ -70,10 +72,7 @@ private static void Run(string name, string poc)
using var snapshot = system.GetSnapshotCache();
using var engine = ApplicationEngine.Create(TriggerType.Application, tx, snapshot, system.GenesisBlock, protocol, tx.SystemFee);
engine.LoadScript(tx.Script);
Stopwatch stopwatch = Stopwatch.StartNew();
engine.Execute();
stopwatch.Stop();
Debug.Assert(engine.State == VMState.FAULT);
Console.WriteLine($"Benchmark: {name},\tTime: {stopwatch.Elapsed}");
}
}
1 change: 1 addition & 0 deletions benchmarks/Neo.Benchmarks/Neo.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Neo\Neo.csproj" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 3 additions & 6 deletions benchmarks/Neo.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo;
using System.Reflection;
using BenchmarkDotNet.Running;
using Neo.Benchmark;

foreach (var method in typeof(Benchmarks).GetMethods(BindingFlags.Public | BindingFlags.Static))
{
method.CreateDelegate<Action>().Invoke();
}
BenchmarkRunner.Run<Benchmarks_PoCs>();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// Benchmarks.cs file belongs to the neo project and is free
// Benchmarks.POC.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
Expand All @@ -9,13 +9,15 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using BenchmarkDotNet.Attributes;
using System.Diagnostics;

namespace Neo.VM
namespace Neo.VM.Benchmark
{
public static class Benchmarks
public class Benchmarks_PoCs
{
public static void NeoIssue2528()
[Benchmark]
public void NeoIssue2528()
{
// https://github.com/neo-project/neo/issues/2528
// L01: INITSLOT 1, 0
Expand Down Expand Up @@ -47,7 +49,8 @@ public static void NeoIssue2528()
Run(nameof(NeoIssue2528), "VwEAwkpKAfsHdwARwG8AnXcAbwAl9////xHAzwJwlAAAdwAQzm8AnXcAbwAl9////0U=");
}

public static void NeoVMIssue418()
[Benchmark]
public void NeoVMIssue418()
{
// https://github.com/neo-project/neo-vm/issues/418
// L00: NEWARRAY0
Expand Down Expand Up @@ -81,7 +84,8 @@ public static void NeoVMIssue418()
Run(nameof(NeoVMIssue418), "whBNEcARTRHAVgEB/gGdYBFNEU0SwFMSwFhKJPNFUUU=");
}

public static void NeoIssue2723()
[Benchmark]
public void NeoIssue2723()
{
// L00: INITSSLOT 1
// L01: PUSHINT32 130000
Expand All @@ -102,11 +106,8 @@ private static void Run(string name, string poc)
byte[] script = Convert.FromBase64String(poc);
using ExecutionEngine engine = new();
engine.LoadScript(script);
Stopwatch stopwatch = Stopwatch.StartNew();
engine.Execute();
stopwatch.Stop();
Debug.Assert(engine.State == VMState.HALT);
Console.WriteLine($"Benchmark: {name},\tTime: {stopwatch.Elapsed}");
}
}
}
1 change: 1 addition & 0 deletions benchmarks/Neo.VM.Benchmarks/Neo.VM.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Neo.VM\Neo.VM.csproj" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this is a good change

</ItemGroup>

</Project>
9 changes: 3 additions & 6 deletions benchmarks/Neo.VM.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.VM;
using System.Reflection;
using BenchmarkDotNet.Running;
using Neo.VM.Benchmark;

foreach (var method in typeof(Benchmarks).GetMethods(BindingFlags.Public | BindingFlags.Static))
{
method.CreateDelegate<Action>().Invoke();
}
BenchmarkRunner.Run<Benchmarks_PoCs>();