Skip to content

Commit

Permalink
add - Added Nitrocid.Benchmarks
Browse files Browse the repository at this point in the history
---

This is an internal tool that allows you to benchmark various Nitrocid functions. Currently, it'll stay that way until the development of 0.1.1 starts.

---

Type: add
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Feb 19, 2024
1 parent f4ff2ca commit 1f62781
Show file tree
Hide file tree
Showing 17 changed files with 679 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Nitrocid.sln
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.Sha1", "pub
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.Sha384", "public\Nitrocid.Addons\Nitrocid.Extras.Sha384\Nitrocid.Extras.Sha384.csproj", "{600337A5-0D56-476A-9428-52B1EF665950}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{EA27625C-C2DE-4080-9253-A572114EDC21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Benchmarks", "private\Nitrocid.Benchmarks\Nitrocid.Benchmarks.csproj", "{32EFC1E5-CE9A-457D-BDC3-3EDE638DE5F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -388,6 +392,10 @@ Global
{600337A5-0D56-476A-9428-52B1EF665950}.Debug|Any CPU.Build.0 = Debug|Any CPU
{600337A5-0D56-476A-9428-52B1EF665950}.Release|Any CPU.ActiveCfg = Release|Any CPU
{600337A5-0D56-476A-9428-52B1EF665950}.Release|Any CPU.Build.0 = Release|Any CPU
{32EFC1E5-CE9A-457D-BDC3-3EDE638DE5F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32EFC1E5-CE9A-457D-BDC3-3EDE638DE5F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32EFC1E5-CE9A-457D-BDC3-3EDE638DE5F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32EFC1E5-CE9A-457D-BDC3-3EDE638DE5F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -451,6 +459,8 @@ Global
{CE5F80A9-B27E-4D16-AEBB-A09677E63012} = {B60F276A-FE12-4001-916E-080344ED1FD9}
{BB2BCBE2-1F15-4B5F-927F-172B4B7FE9D4} = {B60F276A-FE12-4001-916E-080344ED1FD9}
{600337A5-0D56-476A-9428-52B1EF665950} = {B60F276A-FE12-4001-916E-080344ED1FD9}
{EA27625C-C2DE-4080-9253-A572114EDC21} = {61916ED1-66D6-4938-9F1A-D0DF38D16E20}
{32EFC1E5-CE9A-457D-BDC3-3EDE638DE5F3} = {EA27625C-C2DE-4080-9253-A572114EDC21}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {424D8E7A-CFEB-40AE-A79C-437D603177FD}
Expand Down
26 changes: 26 additions & 0 deletions private/Nitrocid.Benchmarks/BenchFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

namespace Nitrocid.Benchmarks
{
public abstract class BenchFixture
{
public virtual void Run() { }
}
}
38 changes: 38 additions & 0 deletions private/Nitrocid.Benchmarks/Entry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Nitrocid.ConsoleBase.Colors;
using Nitrocid.ConsoleBase.Writers;

namespace Nitrocid.Benchmarks
{
internal class Entry
{
static void Main(string[] args)
{
if (args.Length == 0)
{
TextWriters.Write("Specify a benchmark to run.", KernelColorType.Error);
return;
}
string benchName = args[0];
FixtureManager.RunBenchmark(benchName);
}
}
}
34 changes: 34 additions & 0 deletions private/Nitrocid.Benchmarks/FixtureManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BenchmarkDotNet.Running;

namespace Nitrocid.Benchmarks
{
internal static class FixtureManager
{
internal static void RunBenchmark(string fixture)
{
// Get the benchmark fixture and run it
var fixtureType = Type.GetType($"Nitrocid.Benchmarks.Fixtures.{fixture}") ??
throw new Exception($"No fixture type called {fixture}.");
BenchmarkRunner.Run(fixtureType);
}
}
}
43 changes: 43 additions & 0 deletions private/Nitrocid.Benchmarks/Fixtures/EncodingAes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BenchmarkDotNet.Attributes;
using Nitrocid.Drivers;
using Nitrocid.Drivers.Encoding;
using Nitrocid.Drivers.RNG;

namespace Nitrocid.Benchmarks.Fixtures
{
public class EncodingAes : BenchFixture
{
private readonly IEncodingDriver encoding = DriverHandler.GetDriver<IEncodingDriver>("Default");
private readonly IRandomDriver random = DriverHandler.GetDriver<IRandomDriver>("Default");

[Benchmark]
public override void Run()
{
encoding.Initialize();
for (int i = 0; i < 1000000; i++)
{
int num = random.Random();
encoding.GetEncodedString($"#{num}");
}
}
}
}
43 changes: 43 additions & 0 deletions private/Nitrocid.Benchmarks/Fixtures/EncodingRsa.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BenchmarkDotNet.Attributes;
using Nitrocid.Drivers;
using Nitrocid.Drivers.Encoding;
using Nitrocid.Drivers.RNG;

namespace Nitrocid.Benchmarks.Fixtures
{
public class EncodingRsa : BenchFixture
{
private readonly IEncodingDriver encoding = DriverHandler.GetDriver<IEncodingDriver>("RSA");
private readonly IRandomDriver random = DriverHandler.GetDriver<IRandomDriver>("Default");

[Benchmark]
public override void Run()
{
encoding.Initialize();
for (int i = 0; i < 1000000; i++)
{
int num = random.Random();
encoding.GetEncodedString($"#{num}");
}
}
}
}
42 changes: 42 additions & 0 deletions private/Nitrocid.Benchmarks/Fixtures/EncryptionSha256.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BenchmarkDotNet.Attributes;
using Nitrocid.Drivers;
using Nitrocid.Drivers.Encryption;
using Nitrocid.Drivers.RNG;

namespace Nitrocid.Benchmarks.Fixtures
{
public class EncryptionSha256 : BenchFixture
{
private readonly IEncryptionDriver encryption = DriverHandler.GetDriver<IEncryptionDriver>("SHA256");
private readonly IRandomDriver random = DriverHandler.GetDriver<IRandomDriver>("Default");

[Benchmark]
public override void Run()
{
for (int i = 0; i < 1000000; i++)
{
int num = random.Random();
encryption.GetEncryptedString($"#{num}");
}
}
}
}
42 changes: 42 additions & 0 deletions private/Nitrocid.Benchmarks/Fixtures/EncryptionSha512.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BenchmarkDotNet.Attributes;
using Nitrocid.Drivers;
using Nitrocid.Drivers.Encryption;
using Nitrocid.Drivers.RNG;

namespace Nitrocid.Benchmarks.Fixtures
{
public class EncryptionSha512 : BenchFixture
{
private readonly IEncryptionDriver encryption = DriverHandler.GetDriver<IEncryptionDriver>("SHA512");
private readonly IRandomDriver random = DriverHandler.GetDriver<IRandomDriver>("Default");

[Benchmark]
public override void Run()
{
for (int i = 0; i < 1000000; i++)
{
int num = random.Random();
encryption.GetEncryptedString($"#{num}");
}
}
}
}
37 changes: 37 additions & 0 deletions private/Nitrocid.Benchmarks/Fixtures/RngDefault.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BenchmarkDotNet.Attributes;
using Nitrocid.Drivers;
using Nitrocid.Drivers.RNG;

namespace Nitrocid.Benchmarks.Fixtures
{
public class RngDefault : BenchFixture
{
private readonly IRandomDriver random = DriverHandler.GetDriver<IRandomDriver>("Default");

[Benchmark]
public override void Run()
{
for (int i = 0; i < 1000000; i++)
random.Random();
}
}
}
37 changes: 37 additions & 0 deletions private/Nitrocid.Benchmarks/Fixtures/RngOptimized.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BenchmarkDotNet.Attributes;
using Nitrocid.Drivers;
using Nitrocid.Drivers.RNG;

namespace Nitrocid.Benchmarks.Fixtures
{
public class RngOptimized : BenchFixture
{
private readonly IRandomDriver random = DriverHandler.GetDriver<IRandomDriver>("Optimized");

[Benchmark]
public override void Run()
{
for (int i = 0; i < 1000000; i++)
random.Random();
}
}
}
Loading

0 comments on commit 1f62781

Please sign in to comment.