You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2022/11/21 01:41:05 UTC
[lucenenet] 01/13: Adds simple benchmark between nuget versions
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch benchmarkdotnet
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit c47729795036b2d3054424d4fd730375970c1898
Author: Shannon <sd...@gmail.com>
AuthorDate: Wed Jul 15 14:29:23 2020 +1000
Adds simple benchmark between nuget versions
---
Lucene.Net.sln | 5 +
.../HomePageScriptBenchmarks.cs | 112 +++++++++++++++++++++
.../Lucene.Net.Tests.BenchmarkDotNet.csproj | 17 ++++
src/Lucene.Net.Tests.BenchmarkDotNet/Program.cs | 26 +++++
4 files changed, 160 insertions(+)
diff --git a/Lucene.Net.sln b/Lucene.Net.sln
index 7f6fa0562..690dcd988 100644
--- a/Lucene.Net.sln
+++ b/Lucene.Net.sln
@@ -258,6 +258,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{4D0ED7D9
src\dotnet\Lucene.Net.CodeAnalysis\tools\install.ps1 = src\dotnet\Lucene.Net.CodeAnalysis\tools\install.ps1
src\dotnet\Lucene.Net.CodeAnalysis\tools\uninstall.ps1 = src\dotnet\Lucene.Net.CodeAnalysis\tools\uninstall.ps1
EndProjectSection
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Tests.BenchmarkDotNet", "src\Lucene.Net.Tests.BenchmarkDotNet\Lucene.Net.Tests.BenchmarkDotNet.csproj", "{0C476146-411E-4C94-8A59-726A5F982A89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lucene.Net.Tests.AllProjects", "src\Lucene.Net.Tests.AllProjects\Lucene.Net.Tests.AllProjects.csproj", "{9880B87D-8D14-476B-B093-9C3AA0DA8B24}"
EndProject
@@ -554,6 +555,10 @@ Global
{9880B87D-8D14-476B-B093-9C3AA0DA8B24}.Release|Any CPU.Build.0 = Release|Any CPU
{8988CDA4-8420-4BEE-869A-66825055EED2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8988CDA4-8420-4BEE-869A-66825055EED2}.Release|Any CPU.ActiveCfg = Debug|Any CPU
+ {0C476146-411E-4C94-8A59-726A5F982A89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0C476146-411E-4C94-8A59-726A5F982A89}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0C476146-411E-4C94-8A59-726A5F982A89}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0C476146-411E-4C94-8A59-726A5F982A89}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/Lucene.Net.Tests.BenchmarkDotNet/HomePageScriptBenchmarks.cs b/src/Lucene.Net.Tests.BenchmarkDotNet/HomePageScriptBenchmarks.cs
new file mode 100644
index 000000000..37ac4b209
--- /dev/null
+++ b/src/Lucene.Net.Tests.BenchmarkDotNet/HomePageScriptBenchmarks.cs
@@ -0,0 +1,112 @@
+using System;
+using BenchmarkDotNet.Attributes;
+using BenchmarkDotNet.Configs;
+using BenchmarkDotNet.Jobs;
+using Lucene.Net.Util;
+using Lucene.Net.Store;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
+using Lucene.Net.Documents;
+using Lucene.Net.Search;
+using System.Diagnostics;
+
+namespace Lucene.Net.Tests.BenchmarkDotNet
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ [MemoryDiagnoser]
+ [Config(typeof(Config))]
+ public class HomePageScriptBenchmarks
+ {
+ private class Config : ManualConfig
+ {
+ public Config()
+ {
+ var baseJob = Job.MediumRun;
+
+ AddJob(baseJob.WithNuGet("Lucene.Net.Analysis.Common", "4.8.0-beta00009").WithId("4.8.0-beta00009"));
+ AddJob(baseJob.WithNuGet("Lucene.Net.Analysis.Common", "4.8.0-beta00008").WithId("4.8.0-beta00008"));
+ AddJob(baseJob.WithNuGet("Lucene.Net.Analysis.Common", "4.8.0-beta00007").WithId("4.8.0-beta00007"));
+ }
+ }
+
+ private const int _directoryWriterIterations = 10;
+ private const int _indexSearchIterations = 25;
+
+ [Benchmark]
+ public void HomePageScript()
+ {
+ // Ensures index backwards compatibility
+ var AppLuceneVersion = LuceneVersion.LUCENE_48;
+
+ for (int d = 0; d < _directoryWriterIterations; d++)
+ {
+ using var dir = new RAMDirectory();
+
+ //create an analyzer to process the text
+ var analyzer = new StandardAnalyzer(AppLuceneVersion);
+
+ //create an index writer
+ var indexConfig = new IndexWriterConfig(AppLuceneVersion, analyzer);
+ using var writer = new IndexWriter(dir, indexConfig);
+
+ for (int i = 0; i < _indexSearchIterations; i++)
+ {
+ var source = new
+ {
+ Name = $"Kermit{i} the Frog{i}",
+ FavoritePhrase = $"The quick{i} brown{i} fox{i} jumps{i} over{i} the lazy{i} dog{i} "
+ };
+ Document doc = new Document
+ {
+ // StringField indexes but doesn't tokenize
+ new StringField("name", source.Name, Field.Store.YES),
+ new TextField("favoritePhrase", source.FavoritePhrase, Field.Store.YES)
+ };
+
+ writer.AddDocument(doc);
+ writer.Flush(triggerMerge: false, applyAllDeletes: false);
+ }
+
+ for (int i = 0; i < _indexSearchIterations; i++)
+ {
+ // search with a phrase
+ var phrase = new MultiPhraseQuery
+ {
+ new Term("favoritePhrase", $"brown{i}"),
+ new Term("favoritePhrase", $"fox{i}")
+ };
+
+ // re-use the writer to get real-time updates
+ using var reader = writer.GetReader(applyAllDeletes: true);
+ var searcher = new IndexSearcher(reader);
+ var hits = searcher.Search(phrase, 20 /* top 20 */).ScoreDocs;
+ Debug.Assert(hits.Length > 0);
+ foreach (var hit in hits)
+ {
+ var foundDoc = searcher.Doc(hit.Doc);
+ var score = hit.Score;
+ var name = foundDoc.Get("name");
+ var favoritePhrase = foundDoc.Get("favoritePhrase");
+ }
+ }
+ }
+ }
+
+ }
+}
diff --git a/src/Lucene.Net.Tests.BenchmarkDotNet/Lucene.Net.Tests.BenchmarkDotNet.csproj b/src/Lucene.Net.Tests.BenchmarkDotNet/Lucene.Net.Tests.BenchmarkDotNet.csproj
new file mode 100644
index 000000000..5d4af5aea
--- /dev/null
+++ b/src/Lucene.Net.Tests.BenchmarkDotNet/Lucene.Net.Tests.BenchmarkDotNet.csproj
@@ -0,0 +1,17 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>netcoreapp3.1</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
+ <PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.1" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00005" />
+ </ItemGroup>
+
+</Project>
diff --git a/src/Lucene.Net.Tests.BenchmarkDotNet/Program.cs b/src/Lucene.Net.Tests.BenchmarkDotNet/Program.cs
new file mode 100644
index 000000000..c65ec225c
--- /dev/null
+++ b/src/Lucene.Net.Tests.BenchmarkDotNet/Program.cs
@@ -0,0 +1,26 @@
+using BenchmarkDotNet.Running;
+
+namespace Lucene.Net.Tests.BenchmarkDotNet
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ class Program
+ {
+ private static void Main(string[] args) => new BenchmarkSwitcher(typeof(Program).Assembly).Run(args);
+ }
+}