Add benchmarks.

This commit is contained in:
2019-05-25 01:17:16 +01:00
parent 2cbc5268f4
commit 9606c624c8
14 changed files with 5355 additions and 83 deletions

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/Claunia.Localization.Benchmark/gettext/es_ES.po" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Claunia.Localization.Test/gettext/es_ES.po" charset="ISO-8859-1" />
</component>
</project>

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownProjectSettings" wasCopied="true">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true" openRemoteLinks="true" replaceUnicodeEmoji="false" lastLayoutSetsDefault="false">
<PanelProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
</PanelProvider>
</PreviewSettings>
<ParserSettings gitHubSyntaxChange="false" emojiShortcuts="1" emojiImages="0">
<PegdownExtensions>
<option name="ABBREVIATIONS" value="false" />
<option name="ANCHORLINKS" value="true" />
<option name="ASIDE" value="false" />
<option name="ATXHEADERSPACE" value="true" />
<option name="AUTOLINKS" value="true" />
<option name="DEFINITIONS" value="false" />
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="FOOTNOTES" value="false" />
<option name="HARDWRAPS" value="false" />
<option name="HTML_DEEP_PARSER" value="false" />
<option name="INSERTED" value="false" />
<option name="QUOTES" value="false" />
<option name="RELAXEDHRULES" value="true" />
<option name="SMARTS" value="false" />
<option name="STRIKETHROUGH" value="true" />
<option name="SUBSCRIPT" value="false" />
<option name="SUPERSCRIPT" value="false" />
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
<option name="SUPPRESS_INLINE_HTML" value="false" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
<option name="TOC" value="false" />
<option name="WIKILINKS" value="false" />
</PegdownExtensions>
<ParserOptions>
<option name="ADMONITION_EXT" value="false" />
<option name="ATTRIBUTES_EXT" value="false" />
<option name="COMMONMARK_LISTS" value="true" />
<option name="DUMMY" value="false" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="ENUMERATED_REFERENCES_EXT" value="false" />
<option name="FLEXMARK_FRONT_MATTER" value="false" />
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="GITBOOK_URL_ENCODING" value="false" />
<option name="GITHUB_LISTS" value="false" />
<option name="GITHUB_WIKI_LINKS" value="false" />
<option name="GITLAB_EXT" value="false" />
<option name="GITLAB_MATH_EXT" value="false" />
<option name="GITLAB_MERMAID_EXT" value="false" />
<option name="HEADER_ID_NON_ASCII_TO_LOWERCASE" value="false" />
<option name="HEADER_ID_NO_DUPED_DASHES" value="false" />
<option name="JEKYLL_FRONT_MATTER" value="false" />
<option name="MACROS_EXT" value="false" />
<option name="NO_TEXT_ATTRIBUTES" value="false" />
<option name="PARSE_HTML_ANCHOR_ID" value="false" />
<option name="PLANTUML_FENCED_CODE" value="false" />
<option name="PUML_FENCED_CODE" value="false" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true" embedImages="false" embedHttpImages="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" plantUmlConversion="0" mathConversion="-1">
<GeneratorProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
</GeneratorProvider>
<headerTop />
<headerBottom />
<bodyTop />
<bodyBottom />
</HtmlSettings>
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
<StylesheetProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
<cssUriHistory />
</CssSettings>
<AnnotatorSettings targetHasSpaces="true" linkCaseMismatch="true" wikiCaseMismatch="true" wikiLinkHasDashes="true" notUnderWikiHome="true" targetNotWikiPageExt="true" notUnderSourceWikiHome="true" targetNameHasAnchor="true" targetPathHasAnchor="true" wikiLinkHasSlash="true" wikiLinkHasSubdir="true" wikiLinkHasOnlyAnchor="true" linkTargetsWikiHasExt="true" linkTargetsWikiHasBadExt="true" notUnderSameRepo="true" targetNotUnderVcs="false" linkNeedsExt="true" linkHasBadExt="true" linkTargetNeedsExt="true" linkTargetHasBadExt="true" wikiLinkNotInWiki="true" imageTargetNotInRaw="true" repoRelativeAcrossVcsRoots="true" multipleWikiTargetsMatch="true" unresolvedLinkReference="true" linkIsIgnored="true" anchorIsIgnored="true" anchorIsUnresolved="true" anchorLineReferenceIsUnresolved="true" anchorLineReferenceFormat="true" anchorHasDuplicates="true" abbreviationDuplicates="true" abbreviationNotUsed="true" attributeIdDuplicateDefinition="true" attributeIdNotUsed="true" footnoteDuplicateDefinition="true" footnoteUnresolved="true" footnoteDuplicates="true" footnoteNotUsed="true" macroDuplicateDefinition="true" macroUnresolved="true" macroDuplicates="true" macroNotUsed="true" referenceDuplicateDefinition="true" referenceUnresolved="true" referenceDuplicates="true" referenceNotUsed="true" referenceUnresolvedNumericId="true" enumRefDuplicateDefinition="true" enumRefUnresolved="true" enumRefDuplicates="true" enumRefNotUsed="true" enumRefLinkUnresolved="true" enumRefLinkDuplicates="true" simTocUpdateNeeded="true" simTocTitleSpaceNeeded="true" />
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="css" scriptDir="js" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
</project>

View File

@@ -1,88 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownProjectSettings" wasCopied="true">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true" openRemoteLinks="true" replaceUnicodeEmoji="false" lastLayoutSetsDefault="false">
<PanelProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
</PanelProvider>
</PreviewSettings>
<ParserSettings gitHubSyntaxChange="false" emojiShortcuts="1" emojiImages="0">
<PegdownExtensions>
<option name="ABBREVIATIONS" value="false" />
<option name="ANCHORLINKS" value="true" />
<option name="ASIDE" value="false" />
<option name="ATXHEADERSPACE" value="true" />
<option name="AUTOLINKS" value="true" />
<option name="DEFINITIONS" value="false" />
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="FOOTNOTES" value="false" />
<option name="HARDWRAPS" value="false" />
<option name="HTML_DEEP_PARSER" value="false" />
<option name="INSERTED" value="false" />
<option name="QUOTES" value="false" />
<option name="RELAXEDHRULES" value="true" />
<option name="SMARTS" value="false" />
<option name="STRIKETHROUGH" value="true" />
<option name="SUBSCRIPT" value="false" />
<option name="SUPERSCRIPT" value="false" />
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
<option name="SUPPRESS_INLINE_HTML" value="false" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
<option name="TOC" value="false" />
<option name="WIKILINKS" value="false" />
</PegdownExtensions>
<ParserOptions>
<option name="ADMONITION_EXT" value="false" />
<option name="ATTRIBUTES_EXT" value="false" />
<option name="COMMONMARK_LISTS" value="true" />
<option name="DUMMY" value="false" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="ENUMERATED_REFERENCES_EXT" value="false" />
<option name="FLEXMARK_FRONT_MATTER" value="false" />
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="GITBOOK_URL_ENCODING" value="false" />
<option name="GITHUB_LISTS" value="false" />
<option name="GITHUB_WIKI_LINKS" value="false" />
<option name="GITLAB_EXT" value="false" />
<option name="GITLAB_MATH_EXT" value="false" />
<option name="GITLAB_MERMAID_EXT" value="false" />
<option name="HEADER_ID_NON_ASCII_TO_LOWERCASE" value="false" />
<option name="HEADER_ID_NO_DUPED_DASHES" value="false" />
<option name="JEKYLL_FRONT_MATTER" value="false" />
<option name="MACROS_EXT" value="false" />
<option name="NO_TEXT_ATTRIBUTES" value="false" />
<option name="PARSE_HTML_ANCHOR_ID" value="false" />
<option name="PLANTUML_FENCED_CODE" value="false" />
<option name="PUML_FENCED_CODE" value="false" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true" embedImages="false" embedHttpImages="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" plantUmlConversion="0" mathConversion="-1">
<GeneratorProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
</GeneratorProvider>
<headerTop />
<headerBottom />
<bodyTop />
<bodyBottom />
</HtmlSettings>
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
<StylesheetProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
<cssUriHistory />
</CssSettings>
<AnnotatorSettings targetHasSpaces="true" linkCaseMismatch="true" wikiCaseMismatch="true" wikiLinkHasDashes="true" notUnderWikiHome="true" targetNotWikiPageExt="true" notUnderSourceWikiHome="true" targetNameHasAnchor="true" targetPathHasAnchor="true" wikiLinkHasSlash="true" wikiLinkHasSubdir="true" wikiLinkHasOnlyAnchor="true" linkTargetsWikiHasExt="true" linkTargetsWikiHasBadExt="true" notUnderSameRepo="true" targetNotUnderVcs="false" linkNeedsExt="true" linkHasBadExt="true" linkTargetNeedsExt="true" linkTargetHasBadExt="true" wikiLinkNotInWiki="true" imageTargetNotInRaw="true" repoRelativeAcrossVcsRoots="true" multipleWikiTargetsMatch="true" unresolvedLinkReference="true" linkIsIgnored="true" anchorIsIgnored="true" anchorIsUnresolved="true" anchorLineReferenceIsUnresolved="true" anchorLineReferenceFormat="true" anchorHasDuplicates="true" abbreviationDuplicates="true" abbreviationNotUsed="true" attributeIdDuplicateDefinition="true" attributeIdNotUsed="true" footnoteDuplicateDefinition="true" footnoteUnresolved="true" footnoteDuplicates="true" footnoteNotUsed="true" macroDuplicateDefinition="true" macroUnresolved="true" macroDuplicates="true" macroNotUsed="true" referenceDuplicateDefinition="true" referenceUnresolved="true" referenceDuplicates="true" referenceNotUsed="true" referenceUnresolvedNumericId="true" enumRefDuplicateDefinition="true" enumRefUnresolved="true" enumRefDuplicates="true" enumRefNotUsed="true" enumRefLinkUnresolved="true" enumRefLinkDuplicates="true" simTocUpdateNeeded="true" simTocTitleSpaceNeeded="true" />
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="css" scriptDir="js" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
<component name="com.jetbrains.rider.android.RiderAndroidMiscFileCreationComponent">
<option name="ENSURE_MISC_FILE_EXISTS" value="true" />
</component>

View File

@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Benchmark" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/Claunia.Localization.Benchmark/bin/Debug/netcoreapp2.2/Claunia.Localization.Benchmark.dll" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Claunia.Localization.Benchmark" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Claunia.Localization.Benchmark/Claunia.Localization.Benchmark.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value=".NETCoreApp,Version=v2.2" />
<method v="2">
<option name="Build" enabled="true" />
</method>
</configuration>
</component>

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="gettext\es_ES.po">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="gettext\es_ES\LC_MESSAGES\catalog.mo">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Claunia.Localization.Core\Claunia.Localization.Core.csproj" />
<ProjectReference Include="..\Claunia.Localization.Parsers\Claunia.Localization.Parsers.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using BenchmarkDotNet.Attributes;
using Claunia.Localization.Core;
using Claunia.Localization.Parsers;
namespace Claunia.Localization.Benchmark
{
public class Index
{
readonly Core.Localization localization;
public Index()
{
localization = GetText.Parse(Path.Combine(".", "gettext", "es_ES.po"), Encoding.GetEncoding("iso8859-1"));
}
[Benchmark]
public void LinqIndex()
{
Dictionary<string, string> index = new Dictionary<string, string>();
foreach(Message message in localization.Messages)
{
LocalizedString translated = message.Translations.FirstOrDefault(l => l.Locale == "es_ES");
if(translated is null)
{
// TODO: Requested "es" but only "es_ES" exists
int underscore = "es_ES".IndexOf('_');
if(underscore > 0)
translated =
message.Translations.FirstOrDefault(l => l.Locale == "es_ES".Substring(underscore));
}
try { index.Add(message.Id, translated is null ? message.Source.Singular : translated.Singular); }
catch(ArgumentException e)
{
Debug.WriteLine(e);
throw;
}
}
}
}
}

View File

@@ -0,0 +1,16 @@
using System.IO;
using System.Text;
using BenchmarkDotNet.Attributes;
using Claunia.Localization.Parsers;
// ReSharper disable ClassCanBeSealed.Global
namespace Claunia.Localization.Benchmark
{
public class Parser
{
[Benchmark]
public Core.Localization ParseGetText() =>
GetText.Parse(Path.Combine(".", "gettext", "es_ES.po"), Encoding.GetEncoding("iso8859-1"));
}
}

View File

@@ -0,0 +1,15 @@
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
namespace Claunia.Localization.Benchmark
{
class Program
{
static void Main(string[] args)
{
Summary parserBenchmark = BenchmarkRunner.Run<Parser>();
Summary retrievalBenchmark = BenchmarkRunner.Run<Retriever>();
Summary indexBenchmark = BenchmarkRunner.Run<Index>();
}
}
}

View File

@@ -0,0 +1,85 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Claunia.Localization.Benchmark.Resources {
using System;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class LocalizedResources {
private static System.Resources.ResourceManager resourceMan;
private static System.Globalization.CultureInfo resourceCulture;
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal LocalizedResources() {
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
internal static System.Resources.ResourceManager ResourceManager {
get {
if (object.Equals(null, resourceMan)) {
System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Claunia.Localization.Benchmark.Resources.LocalizedResources", typeof(LocalizedResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
internal static System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
internal static string Use_MPEG_VIDEO {
get {
return ResourceManager.GetString("Use_MPEG_VIDEO", resourceCulture);
}
}
internal static string FailedToLoad {
get {
return ResourceManager.GetString("FailedToLoad", resourceCulture);
}
}
internal static string EngineDoesNotSupport {
get {
return ResourceManager.GetString("EngineDoesNotSupport", resourceCulture);
}
}
internal static string SekectActionClickMap {
get {
return ResourceManager.GetString("SekectActionClickMap", resourceCulture);
}
}
internal static string EnabledSubtitles {
get {
return ResourceManager.GetString("EnabledSubtitles", resourceCulture);
}
}
internal static string PreferredDev {
get {
return ResourceManager.GetString("PreferredDev", resourceCulture);
}
}
}
}

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Use_MPEG_VIDEO" xml:space="preserve">
<value>Use MPEG video from the DVD version instead of lower resolution AVI</value>
</data>
<data name="FailedToLoad" xml:space="preserve">
<value>Failed to load saved game from file.</value>
</data>
<data name="EngineDoesNotSupport" xml:space="preserve">
<value>Engine does not support debug level '%s'</value>
</data>
<data name="SekectActionClickMap" xml:space="preserve">
<value>Select an action and click 'Map'</value>
</data>
<data name="EnabledSubtitles" xml:space="preserve">
<value>Subtitles are enabled, but subtitling in King's Quest 7 was unfinished and disabled in the release version of the game. ScummVM allows the subtitles to be re-enabled, but because they were removed from the original game, they do not always render properly or reflect the actual game speech. This is not a ScummVM bug -- it is a problem with the game's assets.</value>
</data>
<data name="PreferredDev" xml:space="preserve">
<value>Preferred Dev.:</value>
</data>
</root>

View File

@@ -0,0 +1,180 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using BenchmarkDotNet.Attributes;
using Claunia.Localization.Benchmark.Resources;
using Claunia.Localization.Core;
using Claunia.Localization.Parsers;
using Mono.Unix;
namespace Claunia.Localization.Benchmark
{
public class Retriever
{
readonly Core.Localization localization;
readonly Dictionary<string, string> localizationIndex;
public Retriever()
{
localization =
GetText.Parse(Path.Combine(".", "gettext", "es_ES.po"), Encoding.GetEncoding("iso8859-1"));
localizationIndex = localization.GetIndex("es_ES");
Catalog.Init("catalog", "./gettext");
}
[Benchmark]
public void MonoCatalog()
{
Catalog.GetString("Use MPEG video from the DVD version instead of lower resolution AVI");
Catalog.GetString("Failed to load saved game from file.");
Catalog.GetString("Engine does not support debug level '%s'");
Catalog.GetString("Select an action and click 'Map'");
Catalog.GetString("" +
"Subtitles are enabled, but subtitling in King's Quest 7 was unfinished and " +
"disabled in the release version of the game. ScummVM allows the subtitles to " +
"be re-enabled, but because they were removed from the original game, they do " +
"not always render properly or reflect the actual game speech. This is not a " +
"ScummVM bug -- it is a problem with the game's assets.");
Catalog.GetString("Preferred Dev.:");
Catalog.GetString("This does not exist");
}
[Benchmark]
public void Indexed()
{
localizationIndex.TryGetValue("Use MPEG video from the DVD version instead of lower resolution AVI", out _);
localizationIndex.TryGetValue("Failed to load saved game from file.", out _);
localizationIndex.TryGetValue("Engine does not support debug level '%s'", out _);
localizationIndex.TryGetValue("Select an action and click 'Map'", out _);
localizationIndex
.TryGetValue("" + "Subtitles are enabled, but subtitling in King's Quest 7 was unfinished and " + "disabled in the release version of the game. ScummVM allows the subtitles to " + "be re-enabled, but because they were removed from the original game, they do " + "not always render properly or reflect the actual game speech. This is not a " + "ScummVM bug -- it is a problem with the game's assets.",
out _);
localizationIndex.TryGetValue("Preferred Dev.:", out _);
localizationIndex.TryGetValue("This does not exist", out _);
}
[Benchmark]
public void DotNetResources()
{
string str1 = LocalizedResources.Use_MPEG_VIDEO;
string str2 = LocalizedResources.FailedToLoad;
string str3 = LocalizedResources.EngineDoesNotSupport;
string str4 = LocalizedResources.SekectActionClickMap;
string str5 = LocalizedResources.EnabledSubtitles;
string str6 = LocalizedResources.PreferredDev;
}
[Benchmark]
public void Linq()
{
GetUsingLinq("Use MPEG video from the DVD version instead of lower resolution AVI");
GetUsingLinq("Failed to load saved game from file.");
GetUsingLinq("Engine does not support debug level '%s'");
GetUsingLinq("Select an action and click 'Map'");
GetUsingLinq("" +
"Subtitles are enabled, but subtitling in King's Quest 7 was unfinished and " +
"disabled in the release version of the game. ScummVM allows the subtitles to " +
"be re-enabled, but because they were removed from the original game, they do " +
"not always render properly or reflect the actual game speech. This is not a " +
"ScummVM bug -- it is a problem with the game's assets.");
GetUsingLinq("Preferred Dev.:");
GetUsingLinq("This does not exist");
}
[Benchmark]
public void Loop()
{
GetUsingLoops("Use MPEG video from the DVD version instead of lower resolution AVI");
GetUsingLoops("Failed to load saved game from file.");
GetUsingLoops("Engine does not support debug level '%s'");
GetUsingLoops("Select an action and click 'Map'");
GetUsingLoops("" +
"Subtitles are enabled, but subtitling in King's Quest 7 was unfinished and " +
"disabled in the release version of the game. ScummVM allows the subtitles to " +
"be re-enabled, but because they were removed from the original game, they do " +
"not always render properly or reflect the actual game speech. This is not a " +
"ScummVM bug -- it is a problem with the game's assets.");
GetUsingLoops("Preferred Dev.:");
GetUsingLoops("This does not exist");
}
string GetUsingLinq(string key)
{
Message message = localization.Messages.FirstOrDefault(m => m.Id == key);
if(message is null) return key;
LocalizedString localized = message.Translations.FirstOrDefault(l => l.Locale == "es_ES");
if(!(localized is null)) return localized.Singular;
int underscore = "es_ES".IndexOf('_');
if(underscore < 0) return key;
localized = message.Translations.FirstOrDefault(l => l.Locale == "es_ES".Substring(0, 2));
return localized?.Singular ?? key;
}
string GetUsingLoops(string key)
{
Message message = null;
foreach(Message msg in localization.Messages)
{
if(msg.Id != key) continue;
message = msg;
break;
}
if(message is null) return key;
LocalizedString sameLocale = null;
LocalizedString majorLocale = null;
LocalizedString similarLocale = null;
switch(message.Translations.Count)
{
case 0: return key;
case 1: return message.Translations[0].Singular;
}
if("es_ES".Length >= 5 && "es_ES"[2] == '_')
{
string subLocale = new string(new[] {"es_ES"[0], "es_ES"[1]});
foreach(LocalizedString translation in message.Translations)
{
if(translation.Locale == "es_ES")
{
sameLocale = translation;
break;
}
if(translation.Locale.Length >= 5 && translation.Locale[0] == subLocale[0] &&
translation.Locale[1] == subLocale[1] && similarLocale is null) similarLocale = translation;
else if(translation.Locale == subLocale && majorLocale is null) majorLocale = translation;
}
return sameLocale?.Singular ?? majorLocale?.Singular ?? similarLocale?.Singular;
}
foreach(LocalizedString translation in message.Translations)
{
if(translation.Locale == "es")
{
sameLocale = translation;
break;
}
if(translation.Locale.Length >= 5 && translation.Locale[0] == "es"[0] &&
translation.Locale[1] == "es"[1] && similarLocale is null) similarLocale = translation;
}
return sameLocale?.Singular ?? similarLocale?.Singular;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Claunia.Localization.Parser
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Claunia.Localization.Test", "Claunia.Localization.Test\Claunia.Localization.Test.csproj", "{76FBD8F7-6AF7-405B-B8F8-3D2F5C655ADD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Claunia.Localization.Benchmark", "Claunia.Localization.Benchmark\Claunia.Localization.Benchmark.csproj", "{6DDAF5A1-ACC2-437D-BC5F-E21441AB2C09}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -38,5 +40,9 @@ Global
{76FBD8F7-6AF7-405B-B8F8-3D2F5C655ADD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76FBD8F7-6AF7-405B-B8F8-3D2F5C655ADD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76FBD8F7-6AF7-405B-B8F8-3D2F5C655ADD}.Release|Any CPU.Build.0 = Release|Any CPU
{6DDAF5A1-ACC2-437D-BC5F-E21441AB2C09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DDAF5A1-ACC2-437D-BC5F-E21441AB2C09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DDAF5A1-ACC2-437D-BC5F-E21441AB2C09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DDAF5A1-ACC2-437D-BC5F-E21441AB2C09}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal