Skip to content

Commit

Permalink
Merge branch 'master' into leveldb-thread-ut
Browse files Browse the repository at this point in the history
  • Loading branch information
NGDAdmin authored Sep 6, 2024
2 parents 1527876 + da193e9 commit 1ced807
Show file tree
Hide file tree
Showing 185 changed files with 5,569 additions and 1,035 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p align="center">
A modern distributed network for the Smart Economy.
<br>
<a href="https://docs.neo.org/docs/en-us/index.html"><strong>Documentation »</strong></a>
<a href="https://developers.neo.org/docs/"><strong>Documentation »</strong></a>
<br>
<br>
<a href="https://github.com/neo-project/neo"><strong>Neo</strong></a>
Expand Down
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}");
}
}
156 changes: 156 additions & 0 deletions benchmarks/Neo.Benchmarks/Benchmarks.UInt160.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// Benchmarks.UInt160.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;

namespace Neo.Benchmark;

public class Benchmarks_UInt160
{
static readonly OldUInt160 s_oldUInt160 = new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
static readonly UInt160 s_newUInt160 = new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);

[Benchmark]
public void TestOldUInt160Gernerator1()
{
_ = new OldUInt160();
}

[Benchmark]
public void TestOldUInt160Gernerator2()
{
_ = new OldUInt160(new byte[20]);
}

[Benchmark]
public void TestOldUInt160CompareTo()
{
OldUInt160.Zero.CompareTo(OldUInt160.Zero);
OldUInt160.Zero.CompareTo(s_oldUInt160);
s_oldUInt160.CompareTo(OldUInt160.Zero);
}

[Benchmark]
public void TestOldUInt160Equals()
{
OldUInt160.Zero.Equals(OldUInt160.Zero);
OldUInt160.Zero.Equals(s_oldUInt160);
s_oldUInt160.Equals(null);
}

[Benchmark]
public void TestOldUInt160Parse()
{
_ = OldUInt160.Parse("0x0000000000000000000000000000000000000000");
_ = OldUInt160.Parse("0000000000000000000000000000000000000000");
}

[Benchmark]
public void TestOldUInt160TryParse()
{
OldUInt160.TryParse(null, out _);
OldUInt160.TryParse("0x0000000000000000000000000000000000000000", out var temp);
OldUInt160.TryParse("0x1230000000000000000000000000000000000000", out temp);
OldUInt160.TryParse("000000000000000000000000000000000000000", out _);
}

[Benchmark]
public void TestOldUInt160OperatorLarger()
{
_ = s_oldUInt160 > OldUInt160.Zero;
}

[Benchmark]
public void TestOldUInt160OperatorLargerAndEqual()
{
_ = s_oldUInt160 >= OldUInt160.Zero;
}

[Benchmark]
public void TestOldUInt160OperatorSmaller()
{
_ = s_oldUInt160 < OldUInt160.Zero;
}

[Benchmark]
public void TestOldUInt160OperatorSmallerAndEqual()
{
_ = s_oldUInt160 <= OldUInt160.Zero;
}

[Benchmark]
public void TestGernerator1()
{
_ = new UInt160();
}

[Benchmark]
public void TestGernerator2()
{
_ = new UInt160(new byte[20]);
}

[Benchmark]
public void TestCompareTo()
{
UInt160.Zero.CompareTo(UInt160.Zero);
UInt160.Zero.CompareTo(s_newUInt160);
s_newUInt160.CompareTo(UInt160.Zero);
}

[Benchmark]
public void TestEquals()
{
UInt160.Zero.Equals(UInt160.Zero);
UInt160.Zero.Equals(s_newUInt160);
s_newUInt160.Equals(null);
}

[Benchmark]
public void TestParse()
{
_ = UInt160.Parse("0x0000000000000000000000000000000000000000");
_ = UInt160.Parse("0000000000000000000000000000000000000000");
}

[Benchmark]
public void TestTryParse()
{
UInt160.TryParse(null, out _);
UInt160.TryParse("0x0000000000000000000000000000000000000000", out var temp);
UInt160.TryParse("0x1230000000000000000000000000000000000000", out temp);
UInt160.TryParse("000000000000000000000000000000000000000", out _);
}

[Benchmark]
public void TestOperatorLarger()
{
_ = s_newUInt160 > UInt160.Zero;
}

[Benchmark]
public void TestOperatorLargerAndEqual()
{
_ = s_newUInt160 >= UInt160.Zero;
}

[Benchmark]
public void TestOperatorSmaller()
{
_ = s_newUInt160 < UInt160.Zero;
}

[Benchmark]
public void TestOperatorSmallerAndEqual()
{
_ = s_newUInt160 <= UInt160.Zero;
}
}
2 changes: 2 additions & 0 deletions benchmarks/Neo.Benchmarks/Neo.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<TargetFrameworks>net8.0</TargetFrameworks>
<RootNamespace>Neo</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

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

<ItemGroup>
Expand Down
Loading

0 comments on commit 1ced807

Please sign in to comment.