First public contribution.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\bench\t_kernbm.cpp
16 // Benchmark the performance of some kernel functions including RTimer
17 // and RThread. Calculation time required for creation & closing of
18 // timer objects, suspension of threads, handling kernel messages, and
19 // the number of threads created and stopped within a fixed time period.
23 // - Calculate and display the time required to create and close 1000
24 // thread-relative timer objects.
25 // - Count and print the time taken to suspend the thread for 100000 times.
26 // - Count and display the time consumed for 100000 kernel messages.
27 // - Get and print the number of threads created and stopped within a
28 // specified timeframe, verify the ExitType, and ExitReason of the threads.
29 // Platforms/Drives/Compatibility:
31 // Assumptions/Requirement/Pre-requisites:
32 // Failures and causes:
33 // Base Port information:
39 #define TIMECOUNT() User::NTickCount()
40 #define TIMEDIFFMS(i,f) (f-i)
42 LOCAL_D RTest test(_L("T_KERNBM"));
47 extern void DummyKernMsg();
53 LOCAL_C TInt ThreadFunction(TAny*)
55 User::WaitForAnyRequest();
59 TInt TestThread(TAny*)
64 TInt TestThreadCreate(TAny*)
67 t.SetPriority(EPriorityAbsoluteVeryLow);
70 t.Create(KNullDesC,TestThread,4096,NULL,NULL);
78 GLDEF_C TInt E32Main()
81 test.Start(_L("Start...\n"));
86 TUint32 c1=TIMECOUNT();
87 for (i=0; i<1000; i++)
94 TUint32 c2=TIMECOUNT();
95 test.Printf(_L("Create and close 1000 timers takes %d ms\n"),TIMEDIFFMS(c1,c2));
98 r=thrd.Create(_L("DodgyThread"),ThreadFunction,4096,1024,8192,NULL);
100 test.Printf(_L("DodgyThread created\n"));
101 thrd.SetPriority(EPriorityMore);
103 test.Printf(_L("DodgyThread resumed\n"));
105 for (i=0; i<100000; i++)
110 test.Printf(_L("Suspend 100000 times takes %d ms\n"),TIMEDIFFMS(c1,c2));
113 test.Printf(_L("DodgyThread killed\n"));
116 for (i=0; i<100000; i++)
121 test.Printf(_L("100000 kernel messages take %d ms\n"),TIMEDIFFMS(c1,c2));
123 test.Next(_L("Create thread test"));
124 r=thrd.Create(_L("Creator"),TestThreadCreate,4096,NULL,NULL);
126 thrd.SetPriority(EPriorityLess);
127 RThread().SetPriority(EPriorityMuchMore);
134 User::After(1000000);
136 User::WaitForRequest(s);
138 test(thrd.ExitType()==EExitKill);
139 test(thrd.ExitReason()==0);
141 test.Printf(_L("%d threads created and stopped in %dms\n"),Count,TIMEDIFFMS(c1,c2));