kerneltest/e32test/bench/t_excbm.cpp
changeset 9 96e5fb8b040d
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 // Copyright (c) 1996-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\bench\t_excbm.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32std_private.h>
       
    20 #include <e32base.h>
       
    21 #include <e32base_private.h>
       
    22 #include <e32test.h>
       
    23 #include <e32svr.h>
       
    24 
       
    25 const TInt KHeapSize=132*1024;
       
    26 const TInt KAverageOverInSeconds=10;
       
    27 const TInt KNumberOfCalculationsPerLoop=20;
       
    28 
       
    29 TInt64 count;
       
    30 
       
    31 RTest test(_L("T_EXCBM"));
       
    32 
       
    33 GLREF_C TInt SlowExec(TAny*);
       
    34 GLREF_C TInt FastExec(TAny*);
       
    35 
       
    36 TInt64 runTest(TThreadFunction aFunction,const TDesC& aTitle)
       
    37     {
       
    38 
       
    39     RThread thread;
       
    40 	TInt r=thread.Create(aTitle,aFunction,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
       
    41 	if(r!=KErrNone)
       
    42 		{
       
    43 		test.Printf(_L("Failed to create thread with error %d\n"),r);
       
    44 		return(r);
       
    45 		}
       
    46     thread.Resume();
       
    47     User::After(1000000);
       
    48     count=0;
       
    49     User::After(KAverageOverInSeconds*1000000);
       
    50     TInt64 result=count;
       
    51     thread.Kill(0);
       
    52 	thread.Close();
       
    53     result *= KNumberOfCalculationsPerLoop;
       
    54     result /= KAverageOverInSeconds;
       
    55     TInt r2 = I64INT(result);
       
    56     test.Printf(_L("%S executed %d in 1 second\n"),&aTitle,r2);
       
    57     return(result);
       
    58     }
       
    59 
       
    60 TInt E32Main()
       
    61 //
       
    62 // Benchmark for Exec functions
       
    63 //
       
    64     {
       
    65 
       
    66     test.Title();
       
    67     test.Start(_L("Benchmarks for Exec functions"));
       
    68     runTest(SlowExec,_L("Slow Exec"));
       
    69     runTest(FastExec,_L("Fast Exec"));
       
    70     test.End();
       
    71 	return(KErrNone);
       
    72     }
       
    73