kerneltest/e32test/bench/t_userbm.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2005-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_userbm.h
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __T_USERBM_H__
       
    19 #define __T_USERBM_H__
       
    20 
       
    21 #include "t_asmbm.h"
       
    22 #include <e32std.h>
       
    23 
       
    24 /// Base class for user benchmarks
       
    25 class TUserBenchmark : public TBmInfo
       
    26 	{
       
    27 public:
       
    28 	virtual void Run(TInt aIts) = 0;
       
    29 protected:
       
    30 	TUserBenchmark(const TDesC8& aName, TUint aCategory);
       
    31 	};
       
    32 
       
    33 class TUserBenchmarkList : public MBenchmarkList
       
    34 	{
       
    35 	virtual TInt Count();
       
    36 	virtual TInt Info(TInt aIndex, TBmInfo& aInfoOut);
       
    37 	virtual TInt Run(TInt aIndex, const TBmParams& aParams, TInt& aDeltaOut);
       
    38 	};
       
    39 
       
    40 /// List containing all defined benchmarks
       
    41 extern RPointerArray<TUserBenchmark> UserBenchmarks;
       
    42 
       
    43 #define CALL_10_TIMES(x) x; x; x; x; x; x; x; x; x; x
       
    44 
       
    45 /// Macro to define a benchmark easily
       
    46 #define DEFINE_USER_BENCHMARK(name, pre, test)         \
       
    47 _LIT8(KName_##name, #name);                            \
       
    48 class TBenchmark_##name : public TUserBenchmark        \
       
    49 	{                                                  \
       
    50 public:                                                \
       
    51 	TBenchmark_##name() :                              \
       
    52          TUserBenchmark(KName_##name, KCategoryGeneral)\
       
    53 		 {}                                            \
       
    54 	virtual void Run(TInt aIts)                        \
       
    55 		{                                              \
       
    56 		pre;                                           \
       
    57 		for (TInt j = 0 ; j < aIts ; ++j)              \
       
    58 			{                                          \
       
    59 			CALL_10_TIMES(test);                       \
       
    60 			}                                          \
       
    61 		}                                              \
       
    62 	} Instance_##name
       
    63 
       
    64 /// Macro to define a benchmark in category 'extra'
       
    65 #define DEFINE_EXTRA_BENCHMARK(name, pre, test)        \
       
    66 _LIT8(KName_##name, #name);                            \
       
    67 class TBenchmark_##name : public TUserBenchmark        \
       
    68 	{                                                  \
       
    69 public:                                                \
       
    70 	TBenchmark_##name() :                              \
       
    71          TUserBenchmark(KName_##name, KCategoryExtra)  \
       
    72 		 {}                                            \
       
    73 	virtual void Run(TInt aIts)                        \
       
    74 		{                                              \
       
    75 		pre;                                           \
       
    76 		for (TInt j = 0 ; j < aIts ; ++j)              \
       
    77 			{                                          \
       
    78 			CALL_10_TIMES(test);                       \
       
    79 			}                                          \
       
    80 		}                                              \
       
    81 	} Instance_##name
       
    82 
       
    83 #endif