Skip to content

Commit d98b1b8

Browse files
committed
feat: Add benchmark debug util
1 parent 9305a8f commit d98b1b8

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Assets/JCSUnity/Scripts/Debug.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* $File: JCS_Benchmark.cs $
3+
* $Date: $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright (c) 2025 by Shen, Jen-Chieh $
8+
*/
9+
using System;
10+
11+
namespace JCSUnity
12+
{
13+
/// <summary>
14+
/// Benchmark operations.
15+
/// </summary>
16+
public static class JCS_Benchmark
17+
{
18+
/* Variables */
19+
20+
/* Setter & Getter */
21+
22+
/* Functions */
23+
24+
/// <summary>
25+
/// Time execution of action.
26+
/// </summary>
27+
/// <param name="times"> Times to execute. </param>
28+
/// <param name="action"> Action to execute. </param>
29+
/// <returns> Return time spent in milliseconds. </returns>
30+
public static int Run(int times, Action action)
31+
{
32+
if (action == null)
33+
return 0;
34+
35+
DateTime before = DateTime.Now;
36+
JCS_Loop.Times(times, (count) =>
37+
{
38+
action.Invoke();
39+
});
40+
41+
DateTime after = DateTime.Now;
42+
TimeSpan duration = after.Subtract(before);
43+
44+
return duration.Milliseconds;
45+
}
46+
}
47+
}

Assets/JCSUnity/Scripts/Debug/JCS_Benchmark.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)