VirtualBox

Changeset 60191 in vbox


Ignore:
Timestamp:
Mar 25, 2016 4:59:31 PM (9 years ago)
Author:
vboxsync
Message:

tstRTPrf: Converted to iprt/test.h and added a little off topic comparison between CPU register and memory based code.

Location:
trunk/src/VBox/Runtime/testcase
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r59675 r60191  
    543543tstPrfRT_TEMPLATE = VBOXR3TSTEXE
    544544tstPrfRT_SOURCES = tstPrfRT.cpp
     545tstPrfRT_SOURCES.x86 = tstRTPrfA.asm
     546tstPrfRT_SOURCES.amd64 = tstRTPrfA.asm
    545547
    546548tstRTPrfIO_TEMPLATE = VBOXR3TSTEXE
  • trunk/src/VBox/Runtime/testcase/tstPrfRT.cpp

    r57358 r60191  
    3232#include <iprt/time.h>
    3333#include <iprt/log.h>
    34 #include <iprt/stream.h>
     34#include <iprt/test.h>
    3535#include <iprt/thread.h>
    3636#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    3737# include <iprt/asm-amd64-x86.h>
    38 
     38#endif
     39
     40
     41/*********************************************************************************************************************************
     42*   Internal Functions                                                                                                           *
     43*********************************************************************************************************************************/
     44#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     45DECLASM(void) tstRTPRfAMemoryAccess(void);
     46DECLASM(void) tstRTPRfARegisterAccess(void);
     47DECLASM(void) tstRTPRfAMemoryUnalignedAccess(void);
     48#endif
     49
     50
     51/*********************************************************************************************************************************
     52*   Global Variables                                                                                                             *
     53*********************************************************************************************************************************/
     54static RTTEST g_hTest;
     55
     56
     57#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    3958
    4059void PrintResult(uint64_t u64Ticks, uint64_t u64MaxTicks, uint64_t u64MinTicks, unsigned cTimes, const char *pszOperation)
    4160{
    42     RTPrintf("tstPrfRT: %-32s %5lld / %5lld / %5lld ticks per call (%u calls %lld ticks)\n",
    43              pszOperation, u64MinTicks, u64Ticks / (uint64_t)cTimes, u64MaxTicks, cTimes, u64Ticks);
     61    //RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
     62    //             "%-32s %5lld / %5lld / %5lld ticks per call (%u calls %lld ticks)\n",
     63    //             pszOperation, u64MinTicks, u64Ticks / (uint64_t)cTimes, u64MaxTicks, cTimes, u64Ticks);
     64    //RTTestValueF(g_hTest, u64MinTicks,                  RTTESTUNIT_NONE, "%s min ticks", pszOperation);
     65    RTTestValueF(g_hTest, u64Ticks / (uint64_t)cTimes,  RTTESTUNIT_NONE, "%s avg ticks", pszOperation);
     66    //RTTestValueF(g_hTest, u64MaxTicks,                  RTTESTUNIT_NONE, "%s max ticks", pszOperation);
    4467}
    4568
     
    91114void PrintResult(uint64_t cNs, uint64_t cNsMax, uint64_t cNsMin, unsigned cTimes, const char *pszOperation)
    92115{
    93     RTPrintf("tstPrfRT: %-32s %5lld / %5lld / %5lld ns per call (%u calls %lld ns)\n",
    94              pszOperation, cNsMin, cNs / (uint64_t)cTimes, cNsMax, cTimes, cNs);
     116    //RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
     117    //             "%-32s %5lld / %5lld / %5lld ns per call (%u calls %lld ns)\n",
     118    //             pszOperation, cNsMin, cNs / (uint64_t)cTimes, cNsMax, cTimes, cNs);
     119    //RTTestValueF(g_hTest, cNsMin,                  RTTESTUNIT_NS_PER_CALL, "%s min", pszOperation);
     120    RTTestValueF(g_hTest, cNs / (uint64_t)cTimes,  RTTESTUNIT_NS_PER_CALL, "%s avg", pszOperation);
     121    //RTTestValueF(g_hTest, cNsMax,                  RTTESTUNIT_NS_PER_CALL, "%s max", pszOperation);
    95122}
    96123
     
    125152    unsigned    i;
    126153
    127     RTR3InitExeNoArguments(argc == 2 ? RTR3INIT_FLAGS_SUPLIB : 0);
    128     RTPrintf("tstPrfRT: TESTING...\n");
     154    RTEXITCODE rcExit = RTTestInitExAndCreate(argc, &argv, argc == 2 ? RTR3INIT_FLAGS_SUPLIB : 0, "tstRTPrf", &g_hTest);
     155    if (rcExit != RTEXITCODE_SUCCESS)
     156        return rcExit;
     157    RTTestBanner(g_hTest);
    129158
    130159    /*
     
    165194    PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTThreadNativeSelf");
    166195
    167     RTPrintf("tstPrtRT: DONE\n");
    168     return 0;
     196#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
     197    /*
     198     * Registers vs stack.
     199     */
     200    ITERATE(RT_NOTHING, tstRTPRfARegisterAccess();, RT_NOTHING, 1000);
     201    uint64_t const cRegTotal = u64TotalTS;
     202    //PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "Register only algorithm");
     203
     204    ITERATE(RT_NOTHING, tstRTPRfAMemoryAccess();, RT_NOTHING, 1000);
     205    uint64_t const cMemTotal = u64TotalTS;
     206    //PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "Memory only algorithm");
     207
     208    ITERATE(RT_NOTHING, tstRTPRfAMemoryUnalignedAccess();, RT_NOTHING, 1000);
     209    uint64_t const cMemUnalignedTotal = u64TotalTS;
     210    //PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "Memory only algorithm");
     211
     212    uint64_t const cSlower100 = cMemTotal * 100 / cRegTotal;
     213    RTTestValue(g_hTest, "Memory instead of registers slowdown", cSlower100, RTTESTUNIT_PCT);
     214    uint64_t const cUnalignedSlower100 = cMemUnalignedTotal * 100 / cRegTotal;
     215    RTTestValue(g_hTest, "Unaligned memory instead of registers slowdown", cUnalignedSlower100, RTTESTUNIT_PCT);
     216#endif
     217
     218    return RTTestSummaryAndDestroy(g_hTest);
    169219}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette