유니티 CSV 라이브러리 성능 분석 (CSV Parsing Performance Test in Unity)
2023. 3. 29. 23:09ㆍUnity
유니티 CSV 라이브러리 성능 분석 (CSV Parsing Performance Test in Unity)
유니티 벤치마크
벤치 마크 테스트
- Open /YourProject/Packages/manifest.json
"com.unity.test-framework.performance": "2.1.0",
"testables": [
"com.unity.test-framework.performance"
]
- Create a new folder Assets/Tests
- Create an assembly definition - Unity.PerformanceTesting
- Check the box “Test Assemblies” and select “Unity.PerformanceTesting” in the Assembly Definition References. Select “Any Platform”
- 결과 - ..\AppData\LocalLow\DefaultCompany\[Project_Name]- TestResults.xml 로그 출력
- ex) Time Microsecond Median:2263.65 Min:2249.03 Max:2392.58 Avg:2278.46 Std:42.87 SampleCount: 9 Sum: 20506.14
- 테스트 코드
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Unity.PerformanceTesting;
public class NewTestScript
{
[Test, Performance]
public void Test()
{
Measure.Method(Counter).Run();
}
private static void Counter()
{
var sum = 0;
for (var i = 0; i < 10000000; i++)
{
sum += i;
}
}
}
파서, 실험 데이터
nuget
- csvhelper 다운로드... 참고
- Assembly Reference 추가 (ex. CSVHelper.dll)
- csv helper api : 결과 Time Millisecond Median:11.65 Min:11.03 Max:12.39 Avg:11.67 Std:0.43 SampleCount: 9 Sum: 105.00
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Unity.PerformanceTesting;
using System.IO;
using System.Globalization;
using CsvHelper;
public class csvpppaser
{
[Test, Performance]
public void Test()
{
Measure.Method(Parser).Run();
}
private static void Parser()
{
var config = new global::CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)
{
CacheFields = true,
};
var writer = new StreamWriter(Application.dataPath + "/Resources/Custom3.txt", true);
var stream = File.OpenRead(Application.dataPath + "/Resources/" + "TestData.csv");
var reader = new StreamReader(stream);
var parser = new CsvParser(reader, config);
while (parser.Read())
{
writer.Write(parser.Record[0]);
}
writer.Flush();
writer.Close();
}
}
- Lumen : Time Millisecond Median:37.64 Min:35.81 Max:44.29 Avg:39.04 Std:2.75 SampleCount: 9 Sum: 351.40
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Unity.PerformanceTesting;
using System.IO;
using System.Globalization;
using LumenWorks;
public class Lumen
{
[Test, Performance]
public void Test()
{
Measure.Method(Parser).Run();
}
private static void Parser()
{
var config = new global::CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)
{
CacheFields = true,
};
var writer = new StreamWriter(Application.dataPath + "/Resources/Custom4.txt", true);
var stream = File.OpenRead(Application.dataPath + "/Resources/" + "TestData.csv");
var reader = new StreamReader(stream);
var csvReader = new LumenWorks.Framework.IO.Csv.CsvReader(reader, hasHeaders: false);
while (csvReader.ReadNextRecord())
{
writer.Write(csvReader[0]);
}
writer.Flush();
writer.Close();
}
}
- CSVTools: Time Millisecond Median:19.92 Min:19.76 Max:22.02 Avg:20.30 Std:0.73 SampleCount: 9 Sum: 182.72
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Unity.PerformanceTesting;
using System.IO;
using System.Globalization;
using System.Linq;
using DataAccess;
public class Tools
{
[Test, Performance]
public void Test()
{
Measure.Method(Parser).Run();
}
private static void Parser()
{
var writer = new StreamWriter(Application.dataPath + "/Resources/Custom5.txt", true);
var table = DataTable.New.ReadLazy(Application.dataPath + "/Resources/" + "TestData.csv");
foreach (var row in table.Rows)
{
writer.Write(row.Values[0]);
}
writer.Flush();
writer.Close();
}
}
- TinyCsvParser: Time Millisecond Median:38.54 Min:37.27 Max:41.53 Avg:39.11 Std:1.63 SampleCount: 9 Sum: 352.02
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Unity.PerformanceTesting;
using System.IO;
using System.Globalization;
using TinyCsvParser;
public class Tiny
{
[Test, Performance]
public void Test()
{
Measure.Method(Parser).Run();
}
private static void Parser()
{
var writer = new StreamWriter(Application.dataPath + "/Resources/Custom5.txt", true);
var stream = File.OpenRead(Application.dataPath + "/Resources/" + "TestData.csv");
var reader = new StreamReader(stream);
var options = new global::TinyCsvParser.Tokenizer.RFC4180.Options('"', '"', ',');
var tokenizer = new global::TinyCsvParser.Tokenizer.RFC4180.RFC4180Tokenizer(options);
string line;
while ((line = reader.ReadLine()) != null)
{
var fields = tokenizer.Tokenize(line);
writer.Write(fields[0]);
}
writer.Flush();
writer.Close();
}
}
- Sylvan : Time Microsecond Median:4298.16 Min:4211.31 Max:4629.84 Avg:4351.92 Std:147.59 SampleCount: 9 Sum: 39167.32
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Unity.PerformanceTesting;
using System.IO;
using System.Globalization;
using Sylvan;
using Sylvan.Data.Csv;
public class SylvanParser
{
[Test, Performance]
public void Test()
{
Measure.Method(Parser).Run();
}
private static void Parser()
{
var writer = new StreamWriter(Application.dataPath + "/Resources/Custom6.txt", true);
var stream = File.OpenRead(Application.dataPath + "/Resources/" + "TestData.csv");
var reader = new StreamReader(stream);
var options = new CsvDataReaderOptions
{
HasHeaders = false,
BufferSize = 0x10000,
};
var csvReader = CsvDataReader.Create(reader, options);
while (csvReader.Read())
{
writer.Write(csvReader.GetString(0));
}
writer.Flush();
writer.Close();
}
}
CsvHelper11.67
String.split | 32 |
Lumen | 39.04 |
CSVTools | 20.3 |
TinyCsvParser | 39.11 |
Sylvan | 4.3 |