8000 Add performance benchmarks for dataframe arithmetic operations (#6827) · dotnet/machinelearning@15e6a55 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15e6a55

Browse files
Add performance benchmarks for dataframe arithmetic operations (#6827)
* Add performance tests * Add extra tests * Fix * Fix typo * Fix Divide_Int16 and Divide_Int32_Int16 benchmarks * Fix * Change csproj file * Update BenchmarkDotNetVersion to 0.13.5 * Fix * Change to 0.13.1 because that is what is latest version in our nuget feeds. --------- Co-authored-by: Jake Radzikowski <JakeRad@Microsoft.com>
1 parent a052146 commit 15e6a55

File tree

8 files changed

+255
-8
lines changed

8 files changed

+255
-8
lines changed

Microsoft.ML.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Tokenizers.Tes
168168
EndProject
169169
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Microsoft.ML.FSharp.Tests", "test\Microsoft.ML.FSharp.Tests\Microsoft.ML.FSharp.Tests.fsproj", "{041CB5CD-5832-413E-A894-D9DBED210B16}"
170170
EndProject
171+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Analysis.PerformanceTests", "test\Microsoft.Data.Analysis.PerformanceTests\Microsoft.Data.Analysis.PerformanceTests.csproj", "{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}"
172+
EndProject
171173
Global
172174
GlobalSection(SolutionConfigurationPlatforms) = preSolution
173175
Debug|Any CPU = Debug|Any CPU
@@ -788,6 +790,14 @@ Global
788790
{041CB5CD-5832-413E-A894-D9DBED210B16}.Release|Any CPU.Build.0 = Release|Any CPU
789791
{041CB5CD-5832-413E-A894-D9DBED210B16}.Release|x64.ActiveCfg = Release|Any CPU
790792
{041CB5CD-5832-413E-A894-D9DBED210B16}.Release|x64.Build.0 = Release|Any CPU
793+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
794+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
795+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Debug|x64.ActiveCfg = Debug|Any CPU
796+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Debug|x64.Build.0 = Debug|Any CPU
797+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
798+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Release|Any CPU.Build.0 = Release|Any CPU
799+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Release|x64.ActiveCfg = Release|Any CPU
800+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD}.Release|x64.Build.0 = Release|Any CPU
791801
EndGlobalSection
792802
GlobalSection(SolutionProperties) = preSolution
793803
HideSolutionNode = FALSE
@@ -870,6 +880,7 @@ Global
870880
{BBC3A950-BD68-45AC-9DBD-A8F4D8847745} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
871881
{C3D82402-F207-4F19-8C57-5AF0FBAF9682} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
872882
{041CB5CD-5832-413E-A894-D9DBED210B16} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
883+
{FB8A8823-CC6C-4C2F-8539-05FBFB7C91CD} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
873884
EndGlobalSection
874885
GlobalSection(ExtensibilityGlobals) = postSolution
875886
SolutionGuid = {41165AF1-35BB-4832-A189-73060F82B01D}

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<SystemCompositionVersion>1.2.0</SystemCompositionVersion>
7575
<!-- Test-only Dependencies -->
7676
<ApprovalTestsVersion>5.4.7</ApprovalTestsVersion>
77-
<BenchmarkDotNetVersion>0.12.0</BenchmarkDotNetVersion>
77+
<BenchmarkDotNetVersion>0.13.1</BenchmarkDotNetVersion>
7878
<DotNetRuntime60Version>6.0.9</DotNetRuntime60Version>
7979
<DotNetRuntime80Version>8.0.0-preview.3.23174.8</DotNetRuntime80Version>
8080
<FluentAssertionVersion>5.10.2</FluentAssertionVersion>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<TargetFrameworks>net6.0</TargetFrameworks>
7+
<GenerateProgramFile>false</GenerateProgramFile>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetVersion)" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\src\Microsoft.Data.Analysis\Microsoft.Data.Analysis.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using BenchmarkDotNet.Attributes;
11+
12+
namespace Microsoft.Data.Analysis.PerformanceTests
13+
{
14+
public class PerformanceTests
15+
{
16+
private const int ItemsCount = 1000000;
17+
18+
private Int32DataFrameColumn _int32Column1;
19+
private Int32DataFrameColumn _int32Column2;
20+
21+
private Int16DataFrameColumn _int16Column1;
22+
private Int16DataFrameColumn _int16Column2;
23+
24+
private DoubleDataFrameColumn _doubleColumn1;
25+
private DoubleDataFrameColumn _doubleColumn2;
26+
27+
private SingleDataFrameColumn _floatColumn1;
28+
private SingleDataFrameColumn _floatColumn2;
29+
30+
[GlobalSetup]
31+
public void SetUp()
32+
{
33+
var values = Enumerable.Range(1, ItemsCount).ToArray();
34+
35+
_int32Column1 = new Int32DataFrameColumn("Column1", values);
36+
_int32Column2 = new Int32DataFrameColumn("Column2", values);
37+
38+
var shortValues = values.Select(v => (short)(v % short.MaxValue + 1)).ToArray();
39+
_int16Column1 = new Int16DataFrameColumn("Column1", shortValues);
40+
_int16Column2 = new Int16DataFrameColumn("Column2", shortValues);
41+
42+
_doubleColumn1 = new DoubleDataFrameColumn("Column1", values.Select(v => (double)v));
43+
_doubleColumn2 = new DoubleDataFrameColumn("Column2", values.Select(v => (double)v));
44+
45+
_floatColumn1 = new SingleDataFrameColumn("Column1", values.Select(v => (float)v));
46+
_floatColumn2 = new SingleDataFrameColumn("Column2", values.Select(v => (float)v));
47+
}
48+
49+
#region Addition
50+
51+
[Benchmark]
52+
public void Add_Int32()
53+
{
54+
var column = _int32Column1 + _int32Column2;
55+
}
56+
57+
[Benchmark]
58+
public void Add_Int16()
59+
{
60+
var column = _int16Column1 + _int16Column2;
61+
}
62+
63+
[Benchmark]
64+
public void Add_Double()
65+
{
66+
var column = _doubleColumn1 + _doubleColumn2;
67+
}
68+
69+
[Benchmark]
70+
public void Add_Float()
71+
{
72+
var column = _floatColumn1 + _floatColumn2;
73+
}
74+
75+
[Benchmark]
76+
public void Add_Int32_Int16()
77+
{
78+
var column = _int32Column1 + _int16Column2;
79+
}
80+
81+
[Benchmark]
82+
public void Add_Double_Float()
83+
{
84+
var column = _doubleColumn1 + _floatColumn2;
85+
}
86+
#endregion
87+
88+
#region Subtract
89+
[Benchmark]
90+
public void Subtract_Int32()
91+
{
92+
var column = _int32Column1 - _int32Column2;
93+
}
94+
95+
[Benchmark]
96+
public void Subtract_Int16()
97+
{
98+
var column = _int16Column1 - _int16Column2;
99+
}
100+
101+
[Benchmark]
102+
public void Subtract_Double()
103+
{
104+
var column = _doubleColumn1 - _doubleColumn2;
105+
}
106+
107+
[Benchmark]
108+
public void Subtract_Float()
109+
{
110+
var column = _floatColumn1 - _floatColumn2;
111+
}
112+
113+
[Benchmark]
114+
public void Subtract_Int32_Int16()
115+
{
116+
var column = _int32Column1 - _int16Column2;
117+
}
118+
119+
[Benchmark]
120+
public void Subtract_Double_Float()
121+
{
122+
var column = _doubleColumn1 - _floatColumn2;
123+
}
124+
#endregion
125+
126+
#region Multiply
127+
[Benchmark]
128+
public void Multiply_Int32()
129+
{
130+
var column = _int32Column1 * _int32Column2;
131+
}
132+
133+
[Benchmark]
134+
public void Multiply_Int16()
135+
{
136+
var column = _int16Column1 * _int16Column2;
137+
}
138+
139+
[Benchmark]
140+
public void Multiply_Double()
141+
{
142+
var column = _doubleColumn1 * _doubleColumn2;
143+
}
144+
145+
[Benchmark]
146+
public void Multiply_Float()
147+
{
148+
var column = _floatColumn1 * _floatColumn2;
149+
}
150+
151+
[Benchmark]
152+
public void Multiply_Int32_Int16()
153+
{
154+
var column = _int32Column1 * _int16Column2;
155+
}
156+
157+
[Benchmark]
158+
public void Multiply_Double_Float()
159+
{
160+
var column = _doubleColumn1 * _floatColumn2;
161+
}
162+
#endregion
163+
164+
#region Divide
165+
[Benchmark]
166+
public void Divide_Int32()
167+
{
168+
var column = _int32Column1 / _int32Column2;
169+
}
170+
171+
[Benchmark]
172+
public void Divide_Int16()
173+
{
174+
var column = _int16Column1 / _int16Column2;
175+
}
176+
177+
[Benchmark]
178+
public void Divide_Double()
179+
{
180+
var column = _doubleColumn1 / _doubleColumn2;
181+
}
182+
183+
[Benchmark]
184+
public void Divide_Float()
185+
{
186+
var column = _floatColumn1 / _floatColumn2;
187+
}
188+
189+
[Benchmark]
190+
public void Divide_Int32_Int16()
191+
{
192+
var column = _int32Column1 / _int16Column2;
193+
}
194+
195+
[Benchmark]
196+
public void Divide_Double_Float()
197+
{
198+
var column = _doubleColumn1 / _floatColumn2;
199+
}
200+
#endregion
201+
}
202+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using BenchmarkDotNet.Running;
6+
7+
8+
namespace Microsoft.Data.Analysis.PerformanceTests
9+
{
10+
class Program
11+
{
12+
public static void Main(string[] args)
13+
{
14+
var summary = BenchmarkRunner.Run<PerformanceTests>();
15+
}
16+
}
17+
}

test/Microsoft.ML.Benchmarks.Tests/BenchmarksTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ where Attribute.IsDefined(type, typeof(CIBenchmark))
5252
[MemberData(nameof(GetBenchmarks))]
5353
public void BenchmarksProjectIsNotBroken(Type type)
5454
{
55-
var summary = BenchmarkRunner.Run(type, new TestConfig().With(new OutputLogger(output)));
55+
var summary = BenchmarkRunner.Run(type, new TestConfig().AddLogger(new OutputLogger(output)));
5656

5757
Assert.False(summary.HasCriticalValidationErrors, "The \"Summary\" should have NOT \"HasCriticalValidationErrors\"");
5858

test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public static void Main(string[] args)
1616
.Run(args, CreateCustomConfig());
1717

1818
private static IConfig CreateCustomConfig()
19-
=> DefaultConfig.Instance
20-
.With(Job.Default
21-
.With(InProcessEmitToolchain.Instance));
19+
=> DefaultConfig.Instance.AddJob(Job.Default
20+
.WithToolchain(InProcessEmitToolchain.Instance));
2221
}
2322
}

test/Microsoft.ML.PerformanceTests/Harness/Configs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public RecommendedConfig()
2020
{
2121
Add(DefaultConfig.Instance); // this config contains all of the basic settings (exporters, columns etc)
2222

23-
Add(GetJobDefinition() // job defines how many times given benchmark should be executed
23+
AddJob(GetJobDefinition()// job defines how many times given benchmark should be executed
2424
.WithCustomBuildConfiguration(GetBuildConfigurationName())
25-
.With(CreateToolchain())); // toolchain is responsible for generating, building and running dedicated executable per benchmark
25+
.WithToolchain(CreateToolchain())); // toolchain is responsible for generating, building and running dedicated executable per benchmark
2626

27-
Add(new ExtraMetricColumn()); // an extra column that can display additional metric reported by the benchmarks
27+
AddColumn(new ExtraMetricColumn()); // an extra column that can display additional metric reported by the benchmarks
2828
}
2929

3030
protected virtual Job GetJobDefinition()

0 commit comments

Comments
 (0)
0