Kavita/API.Benchmark/ParserBenchmarks.cs
Joseph Milazzo f17d89ea47
ComicInfo Refactor (#636)
* Implemented methods to parse out the whole ComicInfo file and a mock ComicInfo from epub files.

* Removed unused imports. ScanSeries needs to cleanup deleted chapters and call RefreshMetadata. Ensure after scan we cleanup tags without any series.

* Random cleanup

* Added some comments about data getting stale and not updating.

* Removed old Summary methods in favor of the ComicInfo versions

* Added a missing property

* Fixed unit test
2021-10-04 16:10:48 -07:00

91 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
namespace API.Benchmark
{
[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[RankColumn]
public class ParserBenchmarks
{
private readonly IList<string> _names;
private static readonly Regex NormalizeRegex = new Regex(@"[^a-zA-Z0-9]",
RegexOptions.IgnoreCase | RegexOptions.Compiled,
TimeSpan.FromMilliseconds(300));
private static readonly Regex IsEpub = new Regex(@"\.epub",
RegexOptions.IgnoreCase | RegexOptions.Compiled,
TimeSpan.FromMilliseconds(300));
public ParserBenchmarks()
{
// Read all series from SeriesNamesForNormalization.txt
_names = File.ReadAllLines("Data/SeriesNamesForNormalization.txt");
Console.WriteLine($"Performing benchmark on {_names.Count} series");
}
private static void NormalizeOriginal(string name)
{
Regex.Replace(name.ToLower(), "[^a-zA-Z0-9]", string.Empty);
}
private static void NormalizeNew(string name)
{
// ReSharper disable once UnusedVariable
var ret = NormalizeRegex.Replace(name, string.Empty).ToLower();
}
[Benchmark]
public void TestNormalizeName()
{
foreach (var name in _names)
{
NormalizeOriginal(name);
}
}
[Benchmark]
public void TestNormalizeName_New()
{
foreach (var name in _names)
{
NormalizeNew(name);
}
}
[Benchmark]
public void TestIsEpub()
{
foreach (var name in _names)
{
if ((name + ".epub").ToLower() == ".epub")
{
/* No Operation */
}
}
}
[Benchmark]
public void TestIsEpub_New()
{
foreach (var name in _names)
{
if (IsEpub.IsMatch((name + ".epub")))
{
/* No Operation */
}
}
}
}
}