fix unit test dotnet yml

This commit is contained in:
Wei Lin 2022-12-27 12:14:52 +08:00
parent 689cf5d78e
commit bb3b1901c2
3 changed files with 4 additions and 87 deletions

View File

@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build

View File

@ -17,6 +17,7 @@
<div align="center">
Your <a href="https://github.com/shps951023/MiniExcel">Star</a> and <a href="https://miniexcel.github.io">Donate</a> can make MiniExcel better
</div>
---
### Introduction

View File

@ -1,84 +0,0 @@
using CsvHelper;
using MiniExcelLibs.Tests.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace MiniExcelLibs.Tests
{
public class PerformanceEnhancementTest
{
[Fact]
public void StartsWithPerformanceCompare()
{
string stringVal = "@@@fileid@@@,tteffadasdas ", findVal = "@@@fileid@@@,";
const int LOOP = 5000000;
int runTimes = 0;
long normalMilliseconds = 0;
long ordinalMilliseconds = 0;
Stopwatch watch = Stopwatch.StartNew();
for (int i = 0; i < LOOP; i++)
{
if (stringVal.StartsWith(findVal))
runTimes++;
}
watch.Stop();
normalMilliseconds = watch.ElapsedMilliseconds;
Assert.Equal(LOOP, runTimes);
runTimes = 0;
watch = Stopwatch.StartNew();
for (int i = 0; i < LOOP; i++)
{
if (stringVal.StartsWith(findVal,StringComparison.Ordinal))
runTimes++;
}
watch.Stop();
ordinalMilliseconds = watch.ElapsedMilliseconds;
Assert.Equal(LOOP, runTimes);
Assert.True(normalMilliseconds > ordinalMilliseconds);
}
[Fact]
public void EndWithPerformanceCompare()
{
string stringVal = "@@@fileid@@@,tteffadasdas ", findVal = " ";
const int LOOP = 5000000;
int runTimes = 0;
long normalMilliseconds = 0;
long ordinalMilliseconds = 0;
Stopwatch watch = Stopwatch.StartNew();
for (int i = 0; i < LOOP; i++)
{
if (stringVal.EndsWith(findVal))
runTimes++;
}
watch.Stop();
normalMilliseconds = watch.ElapsedMilliseconds;
Assert.Equal(LOOP, runTimes);
runTimes = 0;
watch = Stopwatch.StartNew();
for (int i = 0; i < LOOP; i++)
{
if (stringVal.EndsWith(findVal,StringComparison.Ordinal))
runTimes++;
}
watch.Stop();
ordinalMilliseconds = watch.ElapsedMilliseconds;
Assert.Equal(LOOP, runTimes);
Assert.True(normalMilliseconds > ordinalMilliseconds);
}
}
}