-
Notifications
You must be signed in to change notification settings - Fork 1k
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
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
benchmarks/Neo.Benchmarks/Persistence/Bechmarks_LevelDB.cs
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 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// Bechmarks_LevelDB.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.Persistence; | ||
using Neo.Plugins.Storage; | ||
using Neo.SmartContract; | ||
using System.Diagnostics; | ||
|
||
namespace Neo.Benchmarks.Persistence.Benchmarks | ||
{ | ||
public class Bechmarks_LevelDB | ||
{ | ||
// avoid allocations in benchmarks | ||
private static StorageKey key1; | ||
private static readonly byte[] value = new UInt256().GetSpan().ToArray(); | ||
|
||
private const string PathLevelDB = "Data_LevelDB_Benchmarks"; | ||
|
||
private static readonly LevelDBStore levelDb = new(); | ||
private static ISnapshot snapshot; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
if (Directory.Exists(PathLevelDB)) | ||
Directory.Delete(PathLevelDB, true); | ||
|
||
key1 = new KeyBuilder(1, 1).Add(new UInt160()); | ||
|
||
var levelDbStore = levelDb.GetStore(PathLevelDB); | ||
snapshot = levelDbStore.GetSnapshot(); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void Cleanup() | ||
{ | ||
snapshot.Dispose(); | ||
levelDb.Dispose(); | ||
if (Directory.Exists(PathLevelDB)) | ||
Directory.Delete(PathLevelDB, true); | ||
} | ||
|
||
[Benchmark] | ||
public void LevelDBSnapshotWrites() | ||
{ | ||
snapshot.Put(key1.ToArray(), value); | ||
snapshot.Delete(key1.ToArray()); | ||
} | ||
} | ||
} |
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