File size: 22,114 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
class EnProfilerTests : TestFramework
{
	//! Remember this, so we can restore the previous state before the test!
	bool m_bWasProfilerEnabled;
	
	//---------------------------------------------------------------------------
	// Ctor - Decides the tests to run
	//---------------------------------------------------------------------------
	void EnProfilerTests()
	{
		m_bWasProfilerEnabled = EnProfiler.IsEnabledC();
		
		AddInitTest("TestToggling");
		AddInitTest("TestTogglingImmediate");
		AddInitTest("TestSetFlags");
		AddInitTest("TestClearFlags");
		AddInitTest("TestAddFlags");
		AddInitTest("TestModule");
		AddInitTest("TestClassTimeData");
		AddInitTest("TestClassCountData");
		AddInitTest("TestFuncTimeData");
		AddInitTest("TestFuncCountData");		
	}
	
	//---------------------------------------------------------------------------
	// Dtor
	//---------------------------------------------------------------------------
	void ~EnProfilerTests()
	{
		EnProfiler.Enable(m_bWasProfilerEnabled, true);
	}
	
	//---------------------------------------------------------------------------
	// Tests
	//---------------------------------------------------------------------------
	// Test toggling state
	TFResult TestToggling()
	{
		bool currentlyEnabled = EnProfiler.IsEnabledP();
		EnProfiler.Enable(!currentlyEnabled);
		if (Assert(currentlyEnabled != EnProfiler.IsEnabledP()))
		{
			EnProfiler.Enable(currentlyEnabled);				
			return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledP()));
		}
		
		return NTFR(TFR.FAIL);
	}
	
	//---------------------------------------------------------------------------
	// Test toggling immediate state
	TFResult TestTogglingImmediate()
	{
		bool currentlyEnabled = EnProfiler.IsEnabledC();
		EnProfiler.Enable(!currentlyEnabled, true);
		if (Assert(currentlyEnabled != EnProfiler.IsEnabledC()))
		{
			EnProfiler.Enable(currentlyEnabled, true);				
			return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledC()));
		}
		
		return NTFR(TFR.FAIL);
	}
	
	//---------------------------------------------------------------------------
	// Test SetFlags/GetFlags
	TFResult TestSetFlags()
	{
		int currentFlags = EnProfiler.GetFlags();
		
		for (int i = 0; i < EnumTools.GetEnumSize(EnProfilerFlags); ++i)
		{
			int flags = EnumTools.GetEnumValue(EnProfilerFlags, i);
			EnProfiler.SetFlags(flags);
			
			if (!Assert(EnProfiler.GetFlags() == flags))
			{
				EnProfiler.SetFlags(currentFlags);
				return NTFR(TFR.FAIL);
			}
			
			for (int j = 0; j < EnumTools.GetEnumSize(EnProfilerFlags); ++j)
			{
				flags |= EnumTools.GetEnumValue(EnProfilerFlags, j);
				EnProfiler.SetFlags(flags);
				
				if (!Assert(EnProfiler.GetFlags() == flags))
				{
					EnProfiler.SetFlags(currentFlags);
					return NTFR(TFR.FAIL);
				}
			}
		}
		
		// Let's test some bogus
		EnProfiler.SetFlags(-333);
		int bogusFlags = EnProfiler.GetFlags();
		bogusFlags &= ~EnProfilerFlags.ALL;
		if (!Assert(bogusFlags == 0))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		bogusFlags = EnProfiler.SetFlags(6003);
		bogusFlags &= ~EnProfilerFlags.ALL;
		if (!Assert(bogusFlags == 0))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		// Reset
		EnProfiler.SetFlags(currentFlags);		
		return NTFR(TFR.SUCCESS);
	}
	
	//---------------------------------------------------------------------------
	// Test removing of flags
	TFResult TestClearFlags()
	{
		int currentFlags = EnProfiler.GetFlags();
						
		EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE);
		
		if (!Assert(EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE) == EnProfilerFlags.NONE))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
		EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
		
		if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
		EnProfiler.ClearFlags();
		
		if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		// Reset
		EnProfiler.SetFlags(currentFlags);		
		return NTFR(TFR.SUCCESS);
	}
	
	//---------------------------------------------------------------------------
	// Test adding of flags
	TFResult TestAddFlags()
	{
		int currentFlags = EnProfiler.GetFlags();
						
		EnProfiler.ClearFlags();
		
		// Return should match resulting flags
		if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RESET) == EnProfiler.GetFlags()))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.RESET))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE) == (EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE)))
		{
			EnProfiler.SetFlags(currentFlags);
			return NTFR(TFR.FAIL);
		}
		
		// Reset
		EnProfiler.SetFlags(currentFlags);		
		return NTFR(TFR.SUCCESS);
	}
	
	//---------------------------------------------------------------------------
	// Test module
	TFResult TestModule()
	{
		// File lives in Game, use it while testing
		const EnProfilerModule eptModule = EnProfilerModule.GAME;
		
		// This was added at the same time as this API, so check if it works as well
		string nameOfCurrentModule = Type().GetModule();
		if (!Assert(nameOfCurrentModule != ""))
		{
			return NTFR(TFR.FAIL);
		}
		
		// We know we are in Game, so use it as a test
		EnProfilerModule currentModule;
		if (!Assert(EnProfiler.NameToModule(nameOfCurrentModule, currentModule)))
		{
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(currentModule == eptModule))
		{
			return NTFR(TFR.FAIL);
		}
		
		// Test if setting and getting works
		EnProfilerModule currentlyProfiledModule = EnProfiler.GetModule();		
		EnProfiler.SetModule(eptModule);		
		
		if (!Assert(EnProfiler.GetModule() == eptModule))
		{
			EnProfiler.SetModule(currentlyProfiledModule);
			return NTFR(TFR.FAIL);
		}
		
		// Data to restore
		int currentFlags = EnProfiler.GetFlags();
		bool wasEnabled = EnProfiler.RequestImmediateData();
		
		// Make sure we are only profiling Game and that the data is clean
		// Only valid for the Get...Per... methods, as they need to be sorted
		EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE);
		
		// GetTickTime() returns in seconds, so gather the results in seconds too
		int resolution = EnProfiler.GetTimeResolution();
		EnProfiler.SetTimeResolution(1);
		
		// Time to sleeb
		float previousTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
		float timeSlept = Sleep(0.3);
		float postTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
		float diff = postTime - previousTime - timeSlept;
		
		// Restore
		EnProfiler.SetTimeResolution(resolution);		
		
		// We called the function, so it must have some time
		if (!Assert(postTime > 0))
		{
			EnProfiler.SetFlags(currentFlags);
			
			if (!wasEnabled)
				EnProfiler.Enable(false, true);
			
			EnProfiler.SetModule(currentlyProfiledModule);
			
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(diff < 0.00001))
		{
			EnProfiler.SetFlags(currentFlags);			
			
			if (!wasEnabled)
				EnProfiler.Enable(false, true);
			
			EnProfiler.SetModule(currentlyProfiledModule);
			
			return NTFR(TFR.FAIL);
		}
		
		// Clean the session
		EnProfiler.ResetSession(true);
		
		// Something from a different module should not get sorted, so just fire something from a different module
		for (int i = 0; i < 1000; ++i)
		{
			EnumTools.StringToEnum(EnProfilerModule, "MISSION_CUSTOM");
		}
		
		// Sort and gather the data and validate if it is correct
		EnProfiler.SortData();	
		array<ref EnProfilerTimeFuncPair> timePerFunc = {};
		EnProfiler.GetTimePerFunc(timePerFunc);
		
		Debug.TFLog("Game fncs:", this, "TestModule");
		
		int funcCount = timePerFunc.Count();
		for (int j = 0; j < funcCount; ++j)
		{
			EnProfilerTimeFuncPair tfp = timePerFunc[j];
			Debug.TFLog(string.Format("	time: %1 | fnc: %2", tfp.param1, tfp.param2), this, "TestModule");
			// We are currently profiling Game, so this Core function shouldn't be present
			if (!Assert(tfp.param2 != "EnumTools::StringToEnum"))
			{
				EnProfiler.SetFlags(currentFlags);
				
				if (!wasEnabled)
					EnProfiler.Enable(false, true);
				
				EnProfiler.SetModule(currentlyProfiledModule);
				
				return NTFR(TFR.FAIL);
			}
		}
		
		array<ref EnProfilerTimeClassPair> timePerClass = {};
		EnProfiler.GetTimePerClass(timePerClass);
		
		int classCount = timePerClass.Count();
		for (int k = 0; k < classCount; ++k)
		{
			typename type = timePerClass[k].param2;
			EnProfilerModule classModule;
			if (!Assert(EnProfiler.NameToModule(type.GetModule(), classModule)))
			{
				EnProfiler.SetFlags(currentFlags);
				
				if (!wasEnabled)
					EnProfiler.Enable(false, true);
				
				EnProfiler.SetModule(currentlyProfiledModule);
				
				return NTFR(TFR.FAIL);
			}
			
			// Only classes from Game should be present
			if (!Assert(classModule == eptModule))
			{
				EnProfiler.SetFlags(currentFlags);
				
				if (!wasEnabled)
					EnProfiler.Enable(false, true);
				
				EnProfiler.SetModule(currentlyProfiledModule);
				
				return NTFR(TFR.FAIL);
			}
		}
		
		// Now let's check if we can gather the data of what we called earlier by switching the profiled module without resetting the session
		EnProfiler.SetModule(EnProfilerModule.CORE, false);
		EnProfiler.SortData();
		timePerFunc.Clear(); // Let's reuse the array, but the Get...Per... methods only appends to the array, clearing is our responsibility
		EnProfiler.GetTimePerFunc(timePerFunc);
		
		bool found = false;
		
		Debug.TFLog("Core fncs:", this, "TestModule");
		
		funcCount = timePerFunc.Count();
		for (int l = 0; l < funcCount; ++l)
		{
			EnProfilerTimeFuncPair tfpc = timePerFunc[l];
			Debug.TFLog(string.Format("	time: %1 | fnc: %2", tfpc.param1, tfpc.param2), this, "TestModule");
			// We are currently profiling Core, so this Core function should be present
			if (tfpc.param2 == "EnumTools::StringToEnum")
			{
				found = true;
				break;
			}
		}
		
		Assert(found);
		
		// Test some bogus
		EnProfilerModule mod = EnProfiler.GetModule();
		EnProfiler.SetModule(-333);
		bool success = Assert(EnProfiler.GetModule() == mod);
		EnProfiler.SetModule(6003);
		success &= Assert(EnProfiler.GetModule() == mod);
		
		EnProfiler.SetFlags(currentFlags);
		EnProfiler.SetModule(currentlyProfiledModule);
		
		if (!wasEnabled)
			EnProfiler.Enable(false, true);
		
		return BTFR(success && found);
	}
	
	//---------------------------------------------------------------------------
	// Test to see if class time data is correct
	TFResult TestClassTimeData()
	{
		// We should restore this when done
		int resolution = EnProfiler.GetTimeResolution();
		bool wasEnabled = EnProfiler.RequestImmediateData();
		
		// GetTickTime() returns in seconds, so gather the results in seconds too
		EnProfiler.SetTimeResolution(1);
		
		// Create the classes
		EPTHelperClass clss = new EPTHelperClass();
		
		// Time to stress
		float previousTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
		float timeStressed = clss.DoEverything();
		float postTime =  EnProfiler.GetTimeOfClass(clss.Type(), true);
		float postTimeStatic = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true);
		float timeProfiled = postTime - previousTime;
		float diff = Math.AbsFloat(timeProfiled - timeStressed);
		
		Debug.TFLog(string.Format("Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff), this, "TestClassTimeData");
		
		// Restore
		EnProfiler.SetTimeResolution(resolution);
		if (!wasEnabled)
			EnProfiler.Enable(false, true);
		
		// We called the function, so it must have some time
		if (!Assert(postTime > 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(postTime == postTimeStatic))
		{
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(diff < 0.001))
		{
			return NTFR(TFR.FAIL);
		}
		
		return NTFR(TFR.SUCCESS);
	}
	
	//---------------------------------------------------------------------------
	// Test to see if class count data is correct
	TFResult TestClassCountData()
	{
		const int allocAmount = 9;
		const int releaseAmount = 6;
		int remainingAmount = allocAmount - releaseAmount;
		
		// We should restore this when done
		bool wasEnabled = EnProfiler.RequestImmediateData();
		
		// Time to test
		int previousAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
		int previousInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);

		array<ref EPTHelperClass> instanceArr = {};
		for (int i = 0; i < allocAmount; ++i)
		{
			instanceArr.Insert(new EPTHelperClass());
		}
		
		for (int j = 0; j < releaseAmount; ++j)
		{
			delete instanceArr[j];
		}
		
		int postAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
		int postInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
		
		int alloced = postAlloc - previousAlloc;
		int instances = postInstances - previousInstances;
		
		Debug.TFLog(string.Format("Profiling result: alloc: %1 | instances: %2", alloced, instances), this, "TestClassCountData");
		
		// Restore
		if (!wasEnabled)
			EnProfiler.Enable(false, true);
		
		// Time to check
		if (!Assert(alloced == allocAmount))
		{
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(instances == remainingAmount))
		{
			return NTFR(TFR.FAIL);
		}
		
		return NTFR(TFR.SUCCESS);
	}
	
	//---------------------------------------------------------------------------
	// Test to see if func time data is correct
	TFResult TestFuncTimeData()
	{
		// We should restore this when done
		int resolution = EnProfiler.GetTimeResolution();
		bool wasEnabled = EnProfiler.RequestImmediateData();
		
		// GetTickTime() returns in seconds, so gather the results in seconds too
		EnProfiler.SetTimeResolution(1);
		
		// Time to stress
		float previousTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
		float timeStressed = StringFormat();
		float postTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
		float timeProfiled = postTime - previousTime;
		float diff = Math.AbsFloat(timeProfiled - timeStressed);
		
		float previousTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
		float timeStressed2 = StringConcat();
		float postTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
		float timeProfiled2 = postTime2 - previousTime2;
		float diff2 = Math.AbsFloat(timeProfiled2 - timeStressed2);
		
		Debug.TFLog(string.Format("Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2), this, "TestFuncTimeData");
		
		// Restore
		EnProfiler.SetTimeResolution(resolution);
		if (!wasEnabled)
		{
			EnProfiler.Enable(false, true);
		}
		
		// We called the function, so it must have some time
		if (!Assert(postTime > 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(diff < 0.001))
		{
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(postTime2 > 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		if (!Assert(diff2 < 0.001))
		{
			return NTFR(TFR.FAIL);
		}
		
		// I know that string.Format is faster than additive concatenation
		if (!Assert(timeProfiled < timeProfiled2))
		{
			return NTFR(TFR.FAIL);
		}
		
		return NTFR(TFR.SUCCESS);
	}
	
	//---------------------------------------------------------------------------
	// Test to see if func count data is correct
	TFResult TestFuncCountData()
	{
		// We should restore this when done
		bool wasEnabled = EnProfiler.RequestImmediateData();
		
		// Time to count		
		
		// - CallFunction
		int previousCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		GetGame().GameScript.CallFunction(this, "TestFuncCountDataHelper", null, 0);
		int postCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		
		int callCountCF = postCountCF - previousCountCF;
		
		// - CallFunctionParams
		int previousCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		GetGame().GameScript.CallFunctionParams(this, "TestFuncCountDataHelper", null, null);
		int postCountCFP =  EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		
		int callCountCFP = postCountCFP - previousCountCFP;
		
		// - Regular call
		int previousCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		TestFuncCountDataHelper();
		int postCountRG =  EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		
		int callCountRG = postCountRG - previousCountRG;
		
		// - Call
		int previousCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		GetGame().GameScript.Call(this, "TestFuncCountDataHelper", 0);
		int postCountC =  EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
		
		int callCountC = postCountC - previousCountC;
		
		// - Garbage		
		int callCountNon = EnProfiler.GetCountOfFunc("Non Existing Method", Type(), true);
		
		// - Static
		int previousCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
		TestFuncCountDataHelperStatic();
		int postCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
		
		int callCountS = postCountS - previousCountS;
		
		// - Global
		int previousCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
		GetDayZGame();
		int postCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
	
		int callCountG = postCountG - previousCountG;
		
		// - Global proto
		// Not tracked, so don't need to compare before and after, should always be 0
		ErrorEx("Testing global proto call", ErrorExSeverity.INFO);
		int callCountGP = EnProfiler.GetCountOfFuncG("ErrorEx", true);
		
		// - Static proto
		// Not tracked, so don't need to compare before and after, should always be 0
		int callCountSP = EnProfiler.GetCountOfFunc("GetCountOfFunc", StaticGetType(EnProfiler), true);
		
		// - proto
		// Not tracked, so don't need to compare before and after, should always be 0
		GetGame().GetHostName();
		int callCountP = EnProfiler.GetCountOfFunc("GetHostName", GetGame().Type(), true);
		
		// - proto native
		// Not tracked, so don't need to compare before and after, should always be 0
		GetGame().IsServer();
		int callCountPN = EnProfiler.GetCountOfFunc("IsServer", GetGame().Type(), true);
		
		// - static proto native
		// Not tracked, so don't need to compare before and after, should always be 0
		ErrorModuleHandler.GetInstance();
		int callCountSPN = EnProfiler.GetCountOfFunc("GetInstance", StaticGetType(ErrorModuleHandler), true);
		
		// Restore
		if (!wasEnabled)
		{
			EnProfiler.Enable(false, true);
		}
		
		// Do the checks
		
		// - CallFunction
		if (!Assert(callCountCF == 1))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - CallFunctionParams
		if (!Assert(callCountCFP == 1))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - Regular call
		if (!Assert(callCountRG == 1))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - Call
		if (!Assert(callCountC == 1))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - Garbage
		if (!Assert(callCountNon == -1))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - Static
		if (!Assert(callCountS == 1))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - Global
		if (!Assert(callCountG == 1))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - Global proto
		if (!Assert(callCountGP == 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - Static proto
		if (!Assert(callCountSP == 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - proto
		if (!Assert(callCountP == 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - proto native
		if (!Assert(callCountPN == 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		// - static proto native
		if (!Assert(callCountSPN == 0))
		{
			return NTFR(TFR.FAIL);
		}
		
		return NTFR(TFR.SUCCESS);
	}
	
	//---------------------------------------------------------------------------
	// Helpers
	//---------------------------------------------------------------------------
	// Snore
	float Sleep(float timeS)
	{		
		float startTime = GetGame().GetTickTime();
		while (GetGame().GetTickTime() - startTime < timeS)
		{
			// Zzz
		}		
		
		return GetGame().GetTickTime() - startTime;
	}
	
	//---------------------------------------------------------------------------
	// Example stress method
	float StringFormat()
	{		
		float startTime = GetGame().GetTickTime();
		
		for (int i = 0; i < 1000; ++i)
		{
			string example = string.Format("This %1 is %2 just %3 an %4 example %5", i, Type(), this, startTime, "lorem ipsum 1 2 3");
		}	
		
		return GetGame().GetTickTime() - startTime;
	}
	
	//---------------------------------------------------------------------------
	// Example stress method 2
	float StringConcat()
	{		
		float startTime = GetGame().GetTickTime();
		
		for (int i = 0; i < 1000; ++i)
		{
			string example = "This " + i + " is " + Type() + " just " + this + " an " + startTime + " example " + "lorem ipsum 1 2 3";
		}
		
		return GetGame().GetTickTime() - startTime;
	}
	
	//---------------------------------------------------------------------------
	// To make sure it is only ever called in that test
	void TestFuncCountDataHelper()
	{
		int dummy = 3;
	}
	
	//---------------------------------------------------------------------------
	// To make sure it is only ever called in that test
	static void TestFuncCountDataHelperStatic()
	{
		int dummy = 3;
	}
}

class EPTHelperClass
{
	float Sleep2(float timeS)
	{		
		float startTime = GetGame().GetTickTime();
		while (GetGame().GetTickTime() - startTime < timeS)
		{
			// Zzz
		}		
		
		return GetGame().GetTickTime() - startTime;
	}
	float SleepAgain(float timeS)
	{		
		float startTime = GetGame().GetTickTime();
		while (GetGame().GetTickTime() - startTime < timeS)
		{
			// Zzz
		}		
		
		return GetGame().GetTickTime() - startTime;
	}
	
	float DoEverything()
	{
		float startTime = GetGame().GetTickTime();
		
		Sleep2(3);
		SleepAgain(3);
		
		return GetGame().GetTickTime() - startTime;
	}
}