Skip to content

Commit 8b56a20

Browse files
committed
Add benchmarks for Code128 and Codebar encoders, including setup and encoding methods
1 parent 2a19df0 commit 8b56a20

3 files changed

Lines changed: 293 additions & 76 deletions

File tree

.github/workflows/dotnet_benchmark_runner.yml

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@ permissions:
1515

1616
jobs:
1717
benchmark:
18-
name: Performance regression check
18+
name: ${{ matrix.benchmark }} benchmark
1919
runs-on: ubuntu-latest
2020

21+
strategy:
22+
matrix:
23+
benchmark:
24+
- Global
25+
- Ean8Encoder
26+
- Ean13Encoder
27+
- UpcaEncoder
28+
- Isbn13Encoder
29+
- Code93Encoder
30+
- Code39Encoder
31+
- Code128Encoder
32+
- CodabarEncoder
33+
2134
env:
2235
TERM: xterm
2336
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true
@@ -33,87 +46,25 @@ jobs:
3346
uses: actions/setup-dotnet@v4
3447
with:
3548
dotnet-version: 10.x
36-
37-
- name: Run benchmark
38-
run: dotnet run --configuration Release --exporters json --filter '*'
39-
working-directory: Tests/TyKonKet.BarcodeGenerator.CB
40-
41-
- name: Store Global benchmark results
42-
uses: benchmark-action/github-action-benchmark@v1
43-
with:
44-
name: Global
45-
tool: 'benchmarkdotnet'
46-
output-file-path: Tests/TyKonKet.BarcodeGenerator.CB/BenchmarkDotNet.Artifacts/results/TyKonKet.BarcodeGenerator.CB.Benchmarks.Global-report-full-compressed.json
47-
github-token: ${{ secrets.GITHUB_TOKEN }}
48-
auto-push: true
49-
benchmark-data-dir-path: ''
50-
alert-threshold: '200%'
51-
comment-on-alert: true
52-
#summary-always: true
53-
alert-comment-cc-users: '@TyKonKet'
54-
55-
- name: Store Ean8Encoder benchmark results
56-
uses: benchmark-action/github-action-benchmark@v1
57-
with:
58-
name: Ean8Encoder
59-
tool: 'benchmarkdotnet'
60-
output-file-path: Tests/TyKonKet.BarcodeGenerator.CB/BenchmarkDotNet.Artifacts/results/TyKonKet.BarcodeGenerator.CB.Benchmarks.Ean8Encoder-report-full-compressed.json
61-
github-token: ${{ secrets.GITHUB_TOKEN }}
62-
auto-push: true
63-
benchmark-data-dir-path: ''
64-
alert-threshold: '200%'
65-
comment-on-alert: true
66-
#summary-always: true
67-
alert-comment-cc-users: '@TyKonKet'
6849

69-
- name: Store Ean13Encoder benchmark results
70-
uses: benchmark-action/github-action-benchmark@v1
50+
- name: Cache NuGet packages
51+
uses: actions/cache@v4
7152
with:
72-
name: Ean13Encoder
73-
tool: 'benchmarkdotnet'
74-
output-file-path: Tests/TyKonKet.BarcodeGenerator.CB/BenchmarkDotNet.Artifacts/results/TyKonKet.BarcodeGenerator.CB.Benchmarks.Ean13Encoder-report-full-compressed.json
75-
github-token: ${{ secrets.GITHUB_TOKEN }}
76-
auto-push: true
77-
benchmark-data-dir-path: ''
78-
alert-threshold: '200%'
79-
comment-on-alert: true
80-
#summary-always: true
81-
alert-comment-cc-users: '@TyKonKet'
82-
83-
- name: Store UpcaEncoder benchmark results
84-
uses: benchmark-action/github-action-benchmark@v1
85-
with:
86-
name: UpcaEncoder
87-
tool: 'benchmarkdotnet'
88-
output-file-path: Tests/TyKonKet.BarcodeGenerator.CB/BenchmarkDotNet.Artifacts/results/TyKonKet.BarcodeGenerator.CB.Benchmarks.UpcaEncoder-report-full-compressed.json
89-
github-token: ${{ secrets.GITHUB_TOKEN }}
90-
auto-push: true
91-
benchmark-data-dir-path: ''
92-
alert-threshold: '200%'
93-
comment-on-alert: true
94-
#summary-always: true
95-
alert-comment-cc-users: '@TyKonKet'
96-
97-
- name: Store Isbn13Encoder benchmark results
98-
uses: benchmark-action/github-action-benchmark@v1
99-
with:
100-
name: Isbn13Encoder
101-
tool: 'benchmarkdotnet'
102-
output-file-path: Tests/TyKonKet.BarcodeGenerator.CB/BenchmarkDotNet.Artifacts/results/TyKonKet.BarcodeGenerator.CB.Benchmarks.Isbn13Encoder-report-full-compressed.json
103-
github-token: ${{ secrets.GITHUB_TOKEN }}
104-
auto-push: true
105-
benchmark-data-dir-path: ''
106-
alert-threshold: '200%'
107-
comment-on-alert: true
108-
#summary-always: true
109-
alert-comment-cc-users: '@TyKonKet'
53+
path: ~/.nuget/packages
54+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
55+
restore-keys: |
56+
${{ runner.os }}-nuget-
57+
58+
- name: Run ${{ matrix.benchmark }} benchmark
59+
run: dotnet run --configuration Release --exporters json --filter '*${{ matrix.benchmark }}*'
60+
working-directory: Tests/TyKonKet.BarcodeGenerator.CB
11061

111-
- name: Store Code93Encoder benchmark results
62+
- name: Store benchmark results
11263
uses: benchmark-action/github-action-benchmark@v1
11364
with:
114-
name: Code93Encoder
65+
name: ${{ matrix.benchmark }}
11566
tool: 'benchmarkdotnet'
116-
output-file-path: Tests/TyKonKet.BarcodeGenerator.CB/BenchmarkDotNet.Artifacts/results/TyKonKet.BarcodeGenerator.CB.Benchmarks.Code93Encoder-report-full-compressed.json
67+
output-file-path: Tests/TyKonKet.BarcodeGenerator.CB/BenchmarkDotNet.Artifacts/results/TyKonKet.BarcodeGenerator.CB.Benchmarks.${{ matrix.benchmark }}-report-full-compressed.json
11768
github-token: ${{ secrets.GITHUB_TOKEN }}
11869
auto-push: true
11970
benchmark-data-dir-path: ''
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using BenchmarkDotNet.Attributes;
2+
using SkiaSharp;
3+
using TyKonKet.BarcodeGenerator.Fonts;
4+
5+
namespace TyKonKet.BarcodeGenerator.CB.Benchmarks
6+
{
7+
[Config(typeof(BenchmarkConfig))]
8+
public class Code128Encoder
9+
{
10+
private const string BARCODE = "ABC-1234-/+";
11+
12+
private static readonly BarcodeTypes barcodeType = BarcodeTypes.Code128;
13+
14+
private const int HEIGHT = 20;
15+
16+
private const int MARGINS = 1;
17+
18+
private const int SCALING = 5;
19+
20+
private static readonly SKColor backgroundColor = SKColors.White;
21+
22+
private static readonly SKColor foregroundColor = SKColors.Black;
23+
24+
private Barcode encodeWithoutTextEncoder;
25+
26+
private Barcode encodeWithTextEncoder;
27+
28+
[Benchmark]
29+
public Barcode SimpleInstance()
30+
{
31+
return new Barcode(options =>
32+
{
33+
options.Type = barcodeType;
34+
options.Height = HEIGHT;
35+
options.Margins = MARGINS;
36+
options.Scaling = SCALING;
37+
options.BackgroundColor = backgroundColor;
38+
options.ForegroundColor = foregroundColor;
39+
options.RenderText = false;
40+
});
41+
}
42+
43+
[Benchmark]
44+
public Barcode AdvancedInstance()
45+
{
46+
return new Barcode(options =>
47+
{
48+
options.Type = barcodeType;
49+
options.Height = HEIGHT;
50+
options.Margins = MARGINS;
51+
options.Scaling = SCALING;
52+
options.BackgroundColor = backgroundColor;
53+
options.ForegroundColor = foregroundColor;
54+
options.RenderText = true;
55+
options.UseTypeface(FontFamilies.DejaVuSerif, SKFontStyle.Normal);
56+
});
57+
}
58+
59+
#region EncodingWithoutText
60+
61+
[GlobalSetup(Target = nameof(EncodingWithoutText))]
62+
public void EncodingWithoutTextSetup()
63+
{
64+
//Console.WriteLine("Setting up the barcode encoder without text...");
65+
//Console.WriteLine();
66+
67+
encodeWithoutTextEncoder = new Barcode(options =>
68+
{
69+
options.Type = barcodeType;
70+
options.Height = HEIGHT;
71+
options.Margins = MARGINS;
72+
options.Scaling = SCALING;
73+
options.BackgroundColor = backgroundColor;
74+
options.ForegroundColor = foregroundColor;
75+
options.RenderText = false;
76+
});
77+
}
78+
79+
[Benchmark]
80+
public string EncodingWithoutText()
81+
{
82+
return encodeWithoutTextEncoder.Encode(BARCODE);
83+
}
84+
85+
[GlobalCleanup(Target = nameof(EncodingWithoutText))]
86+
public void EncodingWithoutTextCleanup()
87+
{
88+
//Console.WriteLine("Cleaning up the barcode encoder without text...");
89+
//Console.WriteLine();
90+
91+
encodeWithoutTextEncoder?.Dispose();
92+
}
93+
94+
#endregion
95+
96+
#region EncodingWithText
97+
98+
[GlobalSetup(Target = nameof(EncodingWithText))]
99+
public void EncodingWithTextSetup()
100+
{
101+
//Console.WriteLine("Setting up the barcode encoder with text...");
102+
//Console.WriteLine();
103+
104+
encodeWithTextEncoder = new Barcode(options =>
105+
{
106+
options.Type = barcodeType;
107+
options.Height = HEIGHT;
108+
options.Margins = MARGINS;
109+
options.Scaling = SCALING;
110+
options.BackgroundColor = backgroundColor;
111+
options.ForegroundColor = foregroundColor;
112+
options.RenderText = true;
113+
});
114+
}
115+
116+
[Benchmark]
117+
public string EncodingWithText()
118+
{
119+
return encodeWithTextEncoder.Encode(BARCODE);
120+
}
121+
122+
[GlobalCleanup(Target = nameof(EncodingWithText))]
123+
public void EncodingWithTextCleanup()
124+
{
125+
//Console.WriteLine("Cleaning up the barcode encoder with text...");
126+
//Console.WriteLine();
127+
128+
encodeWithTextEncoder?.Dispose();
129+
}
130+
131+
#endregion
132+
}
133+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using BenchmarkDotNet.Attributes;
2+
using SkiaSharp;
3+
using TyKonKet.BarcodeGenerator.Fonts;
4+
5+
namespace TyKonKet.BarcodeGenerator.CB.Benchmarks
6+
{
7+
[Config(typeof(BenchmarkConfig))]
8+
public class CodebarEncoder
9+
{
10+
private const string BARCODE = "A123456A";
11+
12+
private static readonly BarcodeTypes barcodeType = BarcodeTypes.Codabar;
13+
14+
private const int HEIGHT = 20;
15+
16+
private const int MARGINS = 1;
17+
18+
private const int SCALING = 5;
19+
20+
private static readonly SKColor backgroundColor = SKColors.White;
21+
22+
private static readonly SKColor foregroundColor = SKColors.Black;
23+
24+
private Barcode encodeWithoutTextEncoder;
25+
26+
private Barcode encodeWithTextEncoder;
27+
28+
[Benchmark]
29+
public Barcode SimpleInstance()
30+
{
31+
return new Barcode(options =>
32+
{
33+
options.Type = barcodeType;
34+
options.Height = HEIGHT;
35+
options.Margins = MARGINS;
36+
options.Scaling = SCALING;
37+
options.BackgroundColor = backgroundColor;
38+
options.ForegroundColor = foregroundColor;
39+
options.RenderText = false;
40+
});
41+
}
42+
43+
[Benchmark]
44+
public Barcode AdvancedInstance()
45+
{
46+
return new Barcode(options =>
47+
{
48+
options.Type = barcodeType;
49+
options.Height = HEIGHT;
50+
options.Margins = MARGINS;
51+
options.Scaling = SCALING;
52+
options.BackgroundColor = backgroundColor;
53+
options.ForegroundColor = foregroundColor;
54+
options.RenderText = true;
55+
options.UseTypeface(FontFamilies.DejaVuSerif, SKFontStyle.Normal);
56+
});
57+
}
58+
59+
#region EncodingWithoutText
60+
61+
[GlobalSetup(Target = nameof(EncodingWithoutText))]
62+
public void EncodingWithoutTextSetup()
63+
{
64+
//Console.WriteLine("Setting up the barcode encoder without text...");
65+
//Console.WriteLine();
66+
67+
encodeWithoutTextEncoder = new Barcode(options =>
68+
{
69+
options.Type = barcodeType;
70+
options.Height = HEIGHT;
71+
options.Margins = MARGINS;
72+
options.Scaling = SCALING;
73+
options.BackgroundColor = backgroundColor;
74+
options.ForegroundColor = foregroundColor;
75+
options.RenderText = false;
76+
});
77+
}
78+
79+
[Benchmark]
80+
public string EncodingWithoutText()
81+
{
82+
return encodeWithoutTextEncoder.Encode(BARCODE);
83+
}
84+
85+
[GlobalCleanup(Target = nameof(EncodingWithoutText))]
86+
public void EncodingWithoutTextCleanup()
87+
{
88+
//Console.WriteLine("Cleaning up the barcode encoder without text...");
89+
//Console.WriteLine();
90+
91+
encodeWithoutTextEncoder?.Dispose();
92+
}
93+
94+
#endregion
95+
96+
#region EncodingWithText
97+
98+
[GlobalSetup(Target = nameof(EncodingWithText))]
99+
public void EncodingWithTextSetup()
100+
{
101+
//Console.WriteLine("Setting up the barcode encoder with text...");
102+
//Console.WriteLine();
103+
104+
encodeWithTextEncoder = new Barcode(options =>
105+
{
106+
options.Type = barcodeType;
107+
options.Height = HEIGHT;
108+
options.Margins = MARGINS;
109+
options.Scaling = SCALING;
110+
options.BackgroundColor = backgroundColor;
111+
options.ForegroundColor = foregroundColor;
112+
options.RenderText = true;
113+
});
114+
}
115+
116+
[Benchmark]
117+
public string EncodingWithText()
118+
{
119+
return encodeWithTextEncoder.Encode(BARCODE);
120+
}
121+
122+
[GlobalCleanup(Target = nameof(EncodingWithText))]
123+
public void EncodingWithTextCleanup()
124+
{
125+
//Console.WriteLine("Cleaning up the barcode encoder with text...");
126+
//Console.WriteLine();
127+
128+
encodeWithTextEncoder?.Dispose();
129+
}
130+
131+
#endregion
132+
}
133+
}

0 commit comments

Comments
 (0)