-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathFontLoadingBenchmarks.cs
More file actions
75 lines (65 loc) · 2.71 KB
/
FontLoadingBenchmarks.cs
File metadata and controls
75 lines (65 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*************************************************************************************************
Required Notice: Copyright (C) EPPlus Software AB.
This software is licensed under PolyForm Noncommercial License 1.0.0
and may only be used for noncommercial purposes
https://polyformproject.org/licenses/noncommercial/1.0.0/
A commercial license to use this software can be purchased at https://epplussoftware.com
*************************************************************************************************
Date Author Change
*************************************************************************************************
01/20/2025 EPPlus Software AB Initial implementation
*************************************************************************************************/
using BenchmarkDotNet.Attributes;
using EPPlus.Fonts.OpenType;
using OfficeOpenXml.Interfaces.Fonts;
using System.Collections.Generic;
using System.IO;
namespace EPPlus.Fonts.Benchmarks
{
[MemoryDiagnoser]
[SimpleJob(warmupCount: 3, iterationCount: 5)]
public class FontLoadingBenchmarks
{
private List<string> _fontFolders;
[GlobalSetup]
public void Setup()
{
var fontsPath = Path.Combine(System.AppContext.BaseDirectory, "Fonts");
if (!Directory.Exists(fontsPath))
{
throw new DirectoryNotFoundException($"Fonts directory not found: {fontsPath}");
}
_fontFolders = new List<string> { fontsPath };
}
[Benchmark]
public OpenTypeFont Load_Roboto_Regular_ColdCache()
{
OpenTypeFonts.ClearFontCache(); // Clear INNE i benchmark
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);
}
[Benchmark]
public OpenTypeFont Load_Roboto_Regular_WarmCache()
{
// Load UTAN att cleara - använder cache från GlobalSetup eller warmup
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);
}
[Benchmark]
public OpenTypeFont Load_Roboto_Bold_ColdCache()
{
OpenTypeFonts.ClearFontCache();
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Bold);
}
[Benchmark]
public OpenTypeFont Load_Roboto_Italic_ColdCache()
{
OpenTypeFonts.ClearFontCache();
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Italic);
}
[Benchmark]
public OpenTypeFont Load_Roboto_BoldItalic_ColdCache()
{
OpenTypeFonts.ClearFontCache();
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.BoldItalic);
}
}
}