Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: OCR benchmark between IronOcr and Aspose #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions IronBenchmarks.App/IronBenchmarks.App.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
Expand All @@ -33,6 +33,7 @@
<ItemGroup>
<ProjectReference Include="..\IronBenchmarks.BarCodeLibs\IronBenchmarks.BarCodeLibs.csproj" />
<ProjectReference Include="..\IronBenchmarks.ExcelLibs\IronBenchmarks.ExcelLibs.csproj" />
<ProjectReference Include="..\IronBenchmarks.OcrLibs\IronBenchmarks.OcrLibs.csproj" />
<ProjectReference Include="..\IronBenchmarks.PdfLibs\IronBenchmarks.PdfLibs.csproj" />
<ProjectReference Include="..\IronBenchmarks.ReportsEngine\IronBenchmarks.Reporting.csproj" />
</ItemGroup>
Expand Down
24 changes: 23 additions & 1 deletion IronBenchmarks.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Loggers;
Expand All @@ -8,6 +8,7 @@
using IronBenchmarks.App.Configuration;
using IronBenchmarks.BarCodeLibs.Benchmarks;
using IronBenchmarks.ExcelLibs.Benchmarks;
using IronBenchmarks.OcrLibs.Benchmarks;
using IronBenchmarks.PdfLibs.Benchmarks;
using IronBenchmarks.Reporting;
using IronBenchmarks.Reporting.Configuration;
Expand All @@ -27,6 +28,7 @@
RunExcelBenchmarks(args, reportConfig, reportGenerator);
RunPdfBenchmarks(args, reportConfig, reportGenerator);
RunBarCodeBenchmarks(args, reportConfig, reportGenerator);
RunOcrBenchmarks(args, reportConfig, reportGenerator);

Console.ReadKey();

Expand Down Expand Up @@ -111,6 +113,26 @@ static void RunExcelBenchmarks(
_ = reportGenerator.GenerateReport(excelSummaries, "ExcelLibs", libsWithVersions);
}

static void RunOcrBenchmarks(
string[] args,
IReportingConfig reportConfig,
ReportGenerator reportGenerator)
{
if (!args.Contains("-ocr"))
{
return;
}
reportConfig.ReportsFolder += "\\OCR";
var ocrSummaries = new List<Summary>
{
BenchmarkRunner.Run<ReadImage>(),
BenchmarkRunner.Run<Read12MBPdf>(),
BenchmarkRunner.Run<ReadMultipleDocuments>(),
BenchmarkRunner.Run<ReadAndRenderSearchablePdf>(),
};
_ = reportGenerator.GenerateReport(ocrSummaries, "OCR");
}

static Dictionary<string, string> GetLibNamesWithVersions(Type type)
{
var libNames = new Dictionary<string, string>();
Expand Down
4 changes: 2 additions & 2 deletions IronBenchmarks.BarCodeLibs/IronBenchmarks.BarCodeLibs.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>84554a44-3362-4f16-874e-896b2b5196c1</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BarCode" Version="2024.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions IronBenchmarks.ExcelLibs/IronBenchmarks.ExcelLibs.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Aspose.Cells" Version="24.1.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="ClosedXML" Version="0.102.2" />
<PackageReference Include="EPPlus" Version="7.0.6" />
<PackageReference Include="IronXL.Excel" Version="2024.2.11-prerelease" />
Expand Down
40 changes: 40 additions & 0 deletions IronBenchmarks.OcrLibs/Benchmarks/BenchmarkBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.Extensions.Configuration;
using System.Reflection;

namespace IronBenchmarks.OcrLibs.Benchmarks
{
public abstract class BenchmarkBase
{
public BenchmarkBase()
{
SetupLicenses();
EnsureResultsFolderExists();
}

public static void SetupLicenses()
{
IConfigurationBuilder builder = new ConfigurationBuilder()
.AddUserSecrets(Assembly.GetExecutingAssembly(), true);
IConfigurationRoot configuration = builder.Build();
IConfigurationSection appConfig = configuration.GetSection("AppConfig");
string licenseKeyIronOcr = appConfig["LicenseKeyIronOcr"];

IronOcr.License.LicenseKey = licenseKeyIronOcr;
}

public static void EnsureResultsFolderExists()
{
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string reportsFolder = Path.Combine(path ?? "", "Results");

if (!Directory.Exists(reportsFolder))
{
_ = Directory.CreateDirectory(reportsFolder);
}
}

public abstract void Iron_Ocr();

public abstract void Aspose_Ocr();
}
}
35 changes: 35 additions & 0 deletions IronBenchmarks.OcrLibs/Benchmarks/Read12MBPdf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using BenchmarkDotNet.Attributes;
using IronOcr;

namespace IronBenchmarks.OcrLibs.Benchmarks
{
[ShortRunJob]
[MemoryDiagnoser]
public class Read12MBPdf : BenchmarkBase
{
[Benchmark]
public override void Aspose_Ocr()
{
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
var source = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.PDF);
source.Add(@"TestPdfs\linux_commands.pdf");

List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(source);

foreach (Aspose.OCR.RecognitionResult result in results)
{
_ = result.RecognitionText;
}
}

[Benchmark]
public override void Iron_Ocr()
{
var input = new OcrInput();
input.LoadPdf("TestPdfs/linux_commands.pdf");
var ocr = new IronTesseract();
OcrResult result = ocr.Read(input);
_ = result.Text;
}
}
}
44 changes: 44 additions & 0 deletions IronBenchmarks.OcrLibs/Benchmarks/ReadAndRenderSearchablePdf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using BenchmarkDotNet.Attributes;
using IronOcr;

namespace IronBenchmarks.OcrLibs.Benchmarks
{
[ShortRunJob]
[MemoryDiagnoser]
public class ReadAndRenderSearchablePdf : BenchmarkBase
{
[Benchmark]
public override void Aspose_Ocr()
{
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
var source = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.TIFF);
source.Add(@"TestMultiPageImages\test_dw_10.tif");

List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(source);

foreach (Aspose.OCR.RecognitionResult result in results)
{
_ = result.RecognitionText;
}

Aspose.OCR.AsposeOcr.SaveMultipageDocument("aspose_large_tiff.pdf", Aspose.OCR.SaveFormat.Pdf, results);
}

[Benchmark]
public override void Iron_Ocr()
{
var input = new IronOcr.OcrInput();
input.LoadImage(@"TestMultiPageImages\test_dw_10.tif");

var ironTesseract = new IronTesseract();
OcrResult result = ironTesseract.Read(input);

foreach (OcrResult.Page page in result.Pages)
{
_ = page.Text;
}

result.SaveAsSearchablePdf("iron_large_tiff.pdf");
}
}
}
40 changes: 40 additions & 0 deletions IronBenchmarks.OcrLibs/Benchmarks/ReadImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using BenchmarkDotNet.Attributes;
using IronOcr;

namespace IronBenchmarks.OcrLibs.Benchmarks
{
[ShortRunJob]
[MemoryDiagnoser]
public class ReadImage : BenchmarkBase
{
[Benchmark]
public override void Aspose_Ocr()
{
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
var source = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
source.Add(@"TestImages\stock_gs200.jpg");

List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(source);

foreach (Aspose.OCR.RecognitionResult result in results)
{
_ = result.RecognitionText;
}
}

[Benchmark]
public override void Iron_Ocr()
{
var input = new IronOcr.OcrInput();
input.LoadImage(@"TestImages\stock_gs200.jpg");

var ironTesseract = new IronTesseract();
OcrResult result = ironTesseract.Read(input);

foreach (OcrResult.Page page in result.Pages)
{
_ = page.Text;
}
}
}
}
41 changes: 41 additions & 0 deletions IronBenchmarks.OcrLibs/Benchmarks/ReadMultipleDocuments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using BenchmarkDotNet.Attributes;
using IronOcr;

namespace IronBenchmarks.OcrLibs.Benchmarks
{
[ShortRunJob]
[MemoryDiagnoser]
public class ReadMultipleDocuments : BenchmarkBase
{
[Benchmark]
public override void Aspose_Ocr()
{
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
var source = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.Directory);
source.Add("TestImages");

List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(source);

foreach (Aspose.OCR.RecognitionResult result in results)
{
_ = result.RecognitionText;
}
}

[Benchmark]
public override void Iron_Ocr()
{
var input = new IronOcr.OcrInput();
input.LoadImage(@"TestImages\001_20221121000002_S2123457_EL37.tiff");
input.LoadImage(@"TestImages\stock_gs200.jpg");

var ironTesseract = new IronTesseract();
OcrResult result = ironTesseract.Read(input);

foreach (OcrResult.Page page in result.Pages)
{
_ = page.Text;
}
}
}
}
34 changes: 34 additions & 0 deletions IronBenchmarks.OcrLibs/IronBenchmarks.OcrLibs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspose.OCR" Version="24.12.0" />
<PackageReference Include="IronOcr" Version="2025.2.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="TestImages\001_20221121000002_S2123457_EL37.tiff">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestImages\stock_gs200.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestMultiPageImages\test_dw_10.tif">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestPdfs\example.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestPdfs\linux_commands.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IronBenchmarks.OcrLibs/TestImages/t1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added IronBenchmarks.OcrLibs/TestPdfs/example.pdf
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions IronBenchmarks.PdfLibs/IronBenchmarks.PdfLibs.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="IronPdf" Version="2024.1.20" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="iTextSharp" Version="5.5.13.3" />
<PackageReference Include="itextsharp.xmlworker" Version="5.5.13.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
Expand Down
4 changes: 2 additions & 2 deletions IronBenchmarks.ReportsEngine/IronBenchmarks.Reporting.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="IronXL.Excel" Version="2024.2.11-prerelease" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
</ItemGroup>

Expand Down
Loading
Loading