diff --git a/IronBenchmarks.App/IronBenchmarks.App.csproj b/IronBenchmarks.App/IronBenchmarks.App.csproj index 1ccaa3b..ebeaebc 100644 --- a/IronBenchmarks.App/IronBenchmarks.App.csproj +++ b/IronBenchmarks.App/IronBenchmarks.App.csproj @@ -1,4 +1,4 @@ - + Exe @@ -9,7 +9,7 @@ - + @@ -33,6 +33,7 @@ + diff --git a/IronBenchmarks.App/Program.cs b/IronBenchmarks.App/Program.cs index 7797284..a5796cc 100644 --- a/IronBenchmarks.App/Program.cs +++ b/IronBenchmarks.App/Program.cs @@ -1,4 +1,4 @@ -using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Loggers; @@ -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; @@ -27,6 +28,7 @@ RunExcelBenchmarks(args, reportConfig, reportGenerator); RunPdfBenchmarks(args, reportConfig, reportGenerator); RunBarCodeBenchmarks(args, reportConfig, reportGenerator); +RunOcrBenchmarks(args, reportConfig, reportGenerator); Console.ReadKey(); @@ -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 + { + BenchmarkRunner.Run(), + BenchmarkRunner.Run(), + BenchmarkRunner.Run(), + BenchmarkRunner.Run(), + }; + _ = reportGenerator.GenerateReport(ocrSummaries, "OCR"); +} + static Dictionary GetLibNamesWithVersions(Type type) { var libNames = new Dictionary(); diff --git a/IronBenchmarks.BarCodeLibs/IronBenchmarks.BarCodeLibs.csproj b/IronBenchmarks.BarCodeLibs/IronBenchmarks.BarCodeLibs.csproj index 1010acc..3432ded 100644 --- a/IronBenchmarks.BarCodeLibs/IronBenchmarks.BarCodeLibs.csproj +++ b/IronBenchmarks.BarCodeLibs/IronBenchmarks.BarCodeLibs.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,7 +6,7 @@ - + diff --git a/IronBenchmarks.ExcelLibs/IronBenchmarks.ExcelLibs.csproj b/IronBenchmarks.ExcelLibs/IronBenchmarks.ExcelLibs.csproj index 18e92a2..69078a0 100644 --- a/IronBenchmarks.ExcelLibs/IronBenchmarks.ExcelLibs.csproj +++ b/IronBenchmarks.ExcelLibs/IronBenchmarks.ExcelLibs.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,7 @@ - + diff --git a/IronBenchmarks.OcrLibs/Benchmarks/BenchmarkBase.cs b/IronBenchmarks.OcrLibs/Benchmarks/BenchmarkBase.cs new file mode 100644 index 0000000..4192934 --- /dev/null +++ b/IronBenchmarks.OcrLibs/Benchmarks/BenchmarkBase.cs @@ -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(); + } +} diff --git a/IronBenchmarks.OcrLibs/Benchmarks/Read12MBPdf.cs b/IronBenchmarks.OcrLibs/Benchmarks/Read12MBPdf.cs new file mode 100644 index 0000000..6d1670c --- /dev/null +++ b/IronBenchmarks.OcrLibs/Benchmarks/Read12MBPdf.cs @@ -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 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; + } + } +} diff --git a/IronBenchmarks.OcrLibs/Benchmarks/ReadAndRenderSearchablePdf.cs b/IronBenchmarks.OcrLibs/Benchmarks/ReadAndRenderSearchablePdf.cs new file mode 100644 index 0000000..2f8c4f5 --- /dev/null +++ b/IronBenchmarks.OcrLibs/Benchmarks/ReadAndRenderSearchablePdf.cs @@ -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 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"); + } + } +} diff --git a/IronBenchmarks.OcrLibs/Benchmarks/ReadImage.cs b/IronBenchmarks.OcrLibs/Benchmarks/ReadImage.cs new file mode 100644 index 0000000..c69db2a --- /dev/null +++ b/IronBenchmarks.OcrLibs/Benchmarks/ReadImage.cs @@ -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 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; + } + } + } +} diff --git a/IronBenchmarks.OcrLibs/Benchmarks/ReadMultipleDocuments.cs b/IronBenchmarks.OcrLibs/Benchmarks/ReadMultipleDocuments.cs new file mode 100644 index 0000000..6c117d4 --- /dev/null +++ b/IronBenchmarks.OcrLibs/Benchmarks/ReadMultipleDocuments.cs @@ -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 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; + } + } + } +} diff --git a/IronBenchmarks.OcrLibs/IronBenchmarks.OcrLibs.csproj b/IronBenchmarks.OcrLibs/IronBenchmarks.OcrLibs.csproj new file mode 100644 index 0000000..082f56a --- /dev/null +++ b/IronBenchmarks.OcrLibs/IronBenchmarks.OcrLibs.csproj @@ -0,0 +1,34 @@ + + + + net6.0 + enable + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + Always + + + Always + + + + diff --git a/IronBenchmarks.OcrLibs/TestImages/001_20221121000002_S2123457_EL37.tiff b/IronBenchmarks.OcrLibs/TestImages/001_20221121000002_S2123457_EL37.tiff new file mode 100644 index 0000000..9e31aef Binary files /dev/null and b/IronBenchmarks.OcrLibs/TestImages/001_20221121000002_S2123457_EL37.tiff differ diff --git a/IronBenchmarks.OcrLibs/TestImages/stock_gs200.jpg b/IronBenchmarks.OcrLibs/TestImages/stock_gs200.jpg new file mode 100644 index 0000000..702590e Binary files /dev/null and b/IronBenchmarks.OcrLibs/TestImages/stock_gs200.jpg differ diff --git a/IronBenchmarks.OcrLibs/TestImages/t1.jpg b/IronBenchmarks.OcrLibs/TestImages/t1.jpg new file mode 100644 index 0000000..2ff2f8a Binary files /dev/null and b/IronBenchmarks.OcrLibs/TestImages/t1.jpg differ diff --git a/IronBenchmarks.OcrLibs/TestMultiPageImages/test_dw_10.tif b/IronBenchmarks.OcrLibs/TestMultiPageImages/test_dw_10.tif new file mode 100644 index 0000000..09db8f0 Binary files /dev/null and b/IronBenchmarks.OcrLibs/TestMultiPageImages/test_dw_10.tif differ diff --git a/IronBenchmarks.OcrLibs/TestPdfs/example.pdf b/IronBenchmarks.OcrLibs/TestPdfs/example.pdf new file mode 100644 index 0000000..1f915ae Binary files /dev/null and b/IronBenchmarks.OcrLibs/TestPdfs/example.pdf differ diff --git a/IronBenchmarks.OcrLibs/TestPdfs/linux_commands.pdf b/IronBenchmarks.OcrLibs/TestPdfs/linux_commands.pdf new file mode 100644 index 0000000..4e0eddb Binary files /dev/null and b/IronBenchmarks.OcrLibs/TestPdfs/linux_commands.pdf differ diff --git a/IronBenchmarks.PdfLibs/IronBenchmarks.PdfLibs.csproj b/IronBenchmarks.PdfLibs/IronBenchmarks.PdfLibs.csproj index 485ce51..278b1af 100644 --- a/IronBenchmarks.PdfLibs/IronBenchmarks.PdfLibs.csproj +++ b/IronBenchmarks.PdfLibs/IronBenchmarks.PdfLibs.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,7 @@ - + diff --git a/IronBenchmarks.Reporting.Tests/IronBenchmarks.Reporting.Tests.csproj b/IronBenchmarks.Reporting.Tests/IronBenchmarks.Reporting.Tests.csproj index e8880f1..2a609ee 100644 --- a/IronBenchmarks.Reporting.Tests/IronBenchmarks.Reporting.Tests.csproj +++ b/IronBenchmarks.Reporting.Tests/IronBenchmarks.Reporting.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/IronBenchmarks.ReportsEngine/IronBenchmarks.Reporting.csproj b/IronBenchmarks.ReportsEngine/IronBenchmarks.Reporting.csproj index cd7bcc7..c78a78b 100644 --- a/IronBenchmarks.ReportsEngine/IronBenchmarks.Reporting.csproj +++ b/IronBenchmarks.ReportsEngine/IronBenchmarks.Reporting.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -8,7 +8,7 @@ - + diff --git a/IronBenchmarks.sln b/IronBenchmarks.sln index 1a99fcc..329fd6c 100644 --- a/IronBenchmarks.sln +++ b/IronBenchmarks.sln @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronBenchmarks.PdfLibs", "I EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronBenchmarks.BarCodeLibs", "IronBenchmarks.BarCodeLibs\IronBenchmarks.BarCodeLibs.csproj", "{D9DC7796-1BEC-4914-BFBB-974EA19443D8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronBenchmarks.OcrLibs", "IronBenchmarks.OcrLibs\IronBenchmarks.OcrLibs.csproj", "{F31F6750-7C1C-42D3-A3C1-A43646DF3EEB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {D9DC7796-1BEC-4914-BFBB-974EA19443D8}.Debug|Any CPU.Build.0 = Debug|Any CPU {D9DC7796-1BEC-4914-BFBB-974EA19443D8}.Release|Any CPU.ActiveCfg = Release|Any CPU {D9DC7796-1BEC-4914-BFBB-974EA19443D8}.Release|Any CPU.Build.0 = Release|Any CPU + {F31F6750-7C1C-42D3-A3C1-A43646DF3EEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F31F6750-7C1C-42D3-A3C1-A43646DF3EEB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F31F6750-7C1C-42D3-A3C1-A43646DF3EEB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F31F6750-7C1C-42D3-A3C1-A43646DF3EEB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE