VirtualBox

Changeset 6777 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Feb 4, 2008 8:49:41 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27868
Message:

added simple benchmark for low-level assembler instructions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstInlineAsm.cpp

    r6644 r6777  
    921921}
    922922
     923/*
     924 * Make this static. We don't want to have this located on the stack.
     925 */
     926static volatile uint32_t g_u32;
     927
     928#define BENCH(ins, str)  \
     929    RTThreadYield(); \
     930    u64Start = ASMReadTSC(); \
     931    for (i = cRounds; i > 0; i--) \
     932        ins; \
     933    u64Stop = ASMReadTSC(); \
     934    RTPrintf(" %-10s %3llu cycles\n", str, (u64Stop - u64Start) / cRounds);
     935
     936void tstASMBench()
     937{
     938    register unsigned i;
     939    const unsigned cRounds = 1000000;
     940    register uint64_t u64Start, u64Stop;
     941
     942    RTPrintf("Benchmarking some low-level instructions:\n");
     943
     944    BENCH(g_u32 = 0,                         "mov:");
     945    BENCH(ASMAtomicXchgU32(&g_u32, 0),       "xchg:");
     946    BENCH(ASMAtomicCmpXchgU32(&g_u32, 0, 0), "cmpxchg:");
     947
     948    RTPrintf("Done.\n");
     949}
     950
    923951
    924952int main(int argc, char *argv[])
     
    950978    tstASMMemZeroPage();
    951979    tstASMMath();
     980    tstASMBench();
    952981
    953982    /*
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