From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Testing/JobSchedulerTest/Test.sln | 21 ++++ Runtime/Testing/JobSchedulerTest/Test.vcproj | 162 +++++++++++++++++++++++++++ Runtime/Testing/JobSchedulerTest/main.cpp | 82 ++++++++++++++ 3 files changed, 265 insertions(+) create mode 100644 Runtime/Testing/JobSchedulerTest/Test.sln create mode 100644 Runtime/Testing/JobSchedulerTest/Test.vcproj create mode 100644 Runtime/Testing/JobSchedulerTest/main.cpp (limited to 'Runtime/Testing/JobSchedulerTest') diff --git a/Runtime/Testing/JobSchedulerTest/Test.sln b/Runtime/Testing/JobSchedulerTest/Test.sln new file mode 100644 index 0000000..c6f9aa5 --- /dev/null +++ b/Runtime/Testing/JobSchedulerTest/Test.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{4FB80099-804E-4ABE-9680-31290A6F0D89}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {4FB80099-804E-4ABE-9680-31290A6F0D89}.Debug.ActiveCfg = Debug|Win32 + {4FB80099-804E-4ABE-9680-31290A6F0D89}.Debug.Build.0 = Debug|Win32 + {4FB80099-804E-4ABE-9680-31290A6F0D89}.Release.ActiveCfg = Release|Win32 + {4FB80099-804E-4ABE-9680-31290A6F0D89}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/Runtime/Testing/JobSchedulerTest/Test.vcproj b/Runtime/Testing/JobSchedulerTest/Test.vcproj new file mode 100644 index 0000000..58b742f --- /dev/null +++ b/Runtime/Testing/JobSchedulerTest/Test.vcproj @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Runtime/Testing/JobSchedulerTest/main.cpp b/Runtime/Testing/JobSchedulerTest/main.cpp new file mode 100644 index 0000000..8554107 --- /dev/null +++ b/Runtime/Testing/JobSchedulerTest/main.cpp @@ -0,0 +1,82 @@ +#include +#include +#include "UnityPrefix.h" +#include "Runtime/Threads/Thread.h" +#include "Runtime/Threads/Mutex.h" +#include "Runtime/Threads/JobScheduler.h" +#include +#include + +struct WorkData { + float input; + float output; +}; + +void* WorkFunction( void* data ) +{ + WorkData* d = (WorkData*)data; + d->output = 0.0f; + for( int i = 0; i < 1000000; ++i ) { + d->output += sinf(d->output) + cosf(d->input) - sinf(d->output + d->input * 3.0f); + } + + return NULL; +} + +// Windows, Core2Quad 2.40 +// 200 jobs, 100000 iters: +// Sum=590573.192871 +// 0=1.55s 1=0.80s 2=0.55s 3=0.45s 4=0.45s 5=0.44s 6=0.45s +// 100 jobs, 1000000 iters: +// Sum=2992744.398470 +// 0=7.78s 1=3.94s 2=2.66s 3=2.00s 4=2.00s 5=2.00s 6=2.02s + +void DoTests() +{ + JobScheduler scheduler(3,1); + + JobScheduler::JobGroupID group = scheduler.BeginGroup(); + + const int kJobs = 100; + WorkData datas[kJobs]; + for( int i = 0; i < kJobs; ++i ) + { + datas[i].input = i+1; + scheduler.SubmitJob( group, WorkFunction, &datas[i], NULL ); + } + scheduler.WaitForGroup(group); + + float sum = 0.0f; + for( int i = 0; i < kJobs; ++i ) + sum += datas[i].output; + printf("Sum of results: %f\n", sum); +} + + + +int main() +{ + #if UNITY_WIN + DWORD ttt0 = GetTickCount(); + #else + timeval ttt0; + gettimeofday( &ttt0, NULL ); + #endif + + DoTests(); + + #if UNITY_WIN + DWORD ttt1 = GetTickCount(); + float timeTaken = (ttt1-ttt0) * 0.001f; + #else + timeval ttt1; + gettimeofday( &ttt1, NULL ); + timeval ttt2; + timersub( &ttt1, &ttt0, &ttt2 ); + float timeTaken = ttt2.tv_sec + ttt2.tv_usec * 1.0e-6f; + #endif + + printf( "Test time: %.2fs\n", timeTaken ); + + return 0; +} -- cgit v1.1-26-g67d0