home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / system / copymemquicker / source.lha / source / testit.c < prev   
C/C++ Source or Header  |  1992-02-12  |  10KB  |  420 lines

  1. #include <stdio.h>
  2. #include <exec/execbase.h>
  3. #include <clib/timer_protos.h>
  4. #include <pragmas/timer_lib.h>
  5. #define STANDALONE
  6. #include <functions.h>
  7.  
  8. void    *oldcms,
  9.     *newcms,
  10.     *oldcmq,
  11.     *newcmq,
  12.     *naught;
  13. char    *buf1,
  14.     *buf2,
  15.     *buf3,
  16.     *buf4;
  17. ULONG    identity;
  18. BOOL    negative;
  19.  
  20. void            *TimerBase;
  21. struct MsgPort        *tport;
  22. struct timerequest    *treq;
  23. struct timeval        tim1,
  24.             tim2,
  25.             tim3,
  26.             timold,
  27.             timdif,
  28.             totold,
  29.             totnew;
  30. BOOL            has010,
  31.             has020,
  32.             has030;
  33.  
  34. extern struct ExecBase    *SysBase;
  35.  
  36. #define    O_LONG    0
  37. #define O_ODD    1
  38. #define O_EVEN    2
  39.  
  40. void testit(unsigned long loops,unsigned long bytes,long offset);
  41. #pragma regcall(testit(d0,d1,a0))
  42.  
  43. long main(void)
  44. {
  45. #asm
  46.     movea.l    (4).w,a0
  47.     move.l    _LVOCopyMem#+2(a0),a1
  48.     move.l    a1,_newcms
  49.     move.l    _LVOCopyMemQuick#+2(a0),_newcmq
  50.     move.l    -4(a1),_identity
  51.     move.l    -8(a1),_oldcms
  52.     move.l    -12(a1),_oldcmq
  53.     lea    _donaught#,a0
  54.     move.l    a0,_naught
  55. #endasm
  56.     if    (SysBase->LibNode.lib_Version < 37)
  57.     {
  58.         Write(Output(),"You need 2.0 to run this program!\n",34);
  59.         goto warn;
  60.     }
  61.     if    (identity != '*Art')
  62.     {
  63.         Printf("You must run CopyMemQuicker first!\n");
  64. warn:        return 5;
  65.     }
  66.     has030 = FALSE;
  67.     has020 = FALSE;
  68.     has010 = FALSE;
  69.     if    (SysBase->AttnFlags & AFF_68030)
  70.         has030 = TRUE;
  71.     if    (SysBase->AttnFlags & AFF_68020)
  72.         has020 = TRUE;
  73.     else if    (SysBase->AttnFlags & AFF_68010)
  74.         has010 = TRUE;
  75.     tport = CreatePort("cmemtest",0);
  76.     treq = (struct timerequest *)CreateExtIO(tport,(LONG)sizeof(struct timerequest));
  77.     OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest *)treq,0);
  78.     TimerBase = treq->tr_node.io_Device;
  79.     Printf(    "This test will compare the old CopyMem/CopyMemQuick routines with\n"
  80.         "the new ones you have installed.  A great variety of tests will be\n"
  81.         "run, and this might take some time, especially if your system has a\n"
  82.         "slow processor.  All test values are chosen to take a mean time of\n"
  83.         "10 seconds to execute with a 68010 (a middle range processor).\n\n"
  84.         "Initiating test (please be patient...)\n\n");
  85.     if    ((!(buf1 = (char *)malloc(66000)))
  86.     ||    (!(buf2 = (char *)malloc(66000))))
  87.     {
  88.         Printf("Not enough memory to run test!\n");
  89.         return 10;
  90.     }
  91.  
  92.     if    (has030)
  93.     {
  94.         Printf("680%s0 found, prolonging test\n\n",(SysBase->AttnFlags & AFF_68040) ? "4" : "3");
  95.         testit(     79*5,65536,O_ODD);
  96.         testit(    207*5,65536,O_EVEN);
  97.         testit(    207*5,65536,O_LONG);
  98.         testit(   4990*5, 1024,O_ODD);
  99.         testit(  12500*5, 1024,O_EVEN);
  100.         testit(  12500*5, 1024,O_ODD);
  101.         testit(  76200*5,  128,O_LONG);
  102.         testit( 243000*5,   17,O_LONG);
  103.         testit( 322000*5,   16,O_LONG);
  104.         testit( 243000*5,   15,O_LONG);
  105.         testit( 256000*5,   14,O_LONG);
  106.         testit( 464000*5,    8,O_LONG);
  107.         testit( 619000*5,    4,O_LONG);
  108.         testit(1063000*5,    1,O_LONG);
  109.     }
  110.     else if    (has020)
  111.     {
  112.         Printf("680%s0 found, prolonging test\n\n","2");
  113.         testit(     79*3,65536,O_ODD);
  114.         testit(    207*3,65536,O_EVEN);
  115.         testit(    207*3,65536,O_LONG);
  116.         testit(   4990*3, 1024,O_ODD);
  117.         testit(  12500*3, 1024,O_EVEN);
  118.         testit(  12500*3, 1024,O_LONG);
  119.         testit(  76200*3,  128,O_LONG);
  120.         testit( 243000*3,   17,O_LONG);
  121.         testit( 322000*3,   16,O_LONG);
  122.         testit( 243000*3,   15,O_LONG);
  123.         testit( 256000*3,   14,O_LONG);
  124.         testit( 464000*3,    8,O_LONG);
  125.         testit( 619000*3,    4,O_LONG);
  126.         testit(1063000*3,    1,O_LONG);
  127.     }
  128.     else if    (has010)
  129.     {
  130.         testit(     79*1,65536,O_ODD);
  131.         testit(    207*1,65536,O_LONG);
  132.         testit(   4990*1, 1024,O_ODD);
  133.         testit(  12500*1, 1024,O_LONG);
  134.         testit(  76200*1,  128,O_LONG);
  135.         testit( 243000*1,   17,O_LONG);
  136.         testit( 322000*1,   16,O_LONG);
  137.         testit( 243000*1,   15,O_LONG);
  138.         testit( 256000*1,   14,O_LONG);
  139.         testit( 464000*1,    8,O_LONG);
  140.         testit( 619000*1,    4,O_LONG);
  141.         testit(1063000*1,    1,O_LONG);
  142.     }
  143.     else
  144.     {
  145.         Printf("68000 found, shortening test\n\n");
  146.         testit(     79/2,65536,O_ODD);
  147.         testit(    207*1,65536,O_LONG);
  148.         testit(   4990/2, 1024,O_ODD);
  149.         testit(  12500*1, 1024,O_LONG);
  150.         testit(  76200*1,  128,O_LONG);
  151.         testit( 243000*2/3, 17,O_LONG);
  152.         testit( 322000*2/3, 16,O_LONG);
  153.         testit( 243000*2/3, 15,O_LONG);
  154.         testit( 256000*2/3, 14,O_LONG);
  155.         testit( 464000/2,    8,O_LONG);
  156.         testit( 619000/2,    4,O_LONG);
  157.         testit(1063000/2,    1,O_LONG);
  158.     }
  159.  
  160.     free(buf2);
  161.     free(buf1);
  162.     Printf("Total timing:\n-------------\n");
  163.     Printf("%s routines    :%4ld.%02ld secs","Old",totold.tv_secs,totold.tv_micro / 10000);
  164.     if    (has010)
  165.         Printf(" (%s predicted)","203.35");
  166.     Printf("\n");
  167.     Printf("%s routines    :%4ld.%02ld secs","New",totnew.tv_secs,totnew.tv_micro / 10000);
  168.     if    (has010)
  169.         Printf(" (%s predicted)","156.58");
  170.     Printf("\n");
  171.     {
  172.         unsigned long    pctint,
  173.                 hund1,
  174.                 hund2;
  175.         struct timeval    *time3 = &tim3,
  176.                 *totalold = &totold;
  177.  
  178.         time3->tv_secs = totalold->tv_secs;
  179.         time3->tv_micro = totalold->tv_micro;
  180.         SubTime(time3,&totnew);
  181.         if    ((LONG)time3->tv_secs < 0)
  182.         {
  183.             time3->tv_secs = -((LONG)time3->tv_secs + 1);
  184.             time3->tv_micro = 1000000 - time3->tv_micro;
  185.             negative = TRUE;
  186.         }
  187.         else    negative = FALSE;
  188.         hund2 = (time3->tv_secs * 100) + (time3->tv_micro / 10000);
  189.         hund1 = (totalold->tv_secs * 100) + (totalold->tv_micro / 10000);
  190.         pctint = hund2 * 100000 / hund1;
  191.         if    ((pctint % 10) > 5)
  192.             pctint += 10;
  193.         pctint /= 10;
  194.         Printf("Total s%s\t:%4ld.%02ld %%   ",(negative) ? "lowdown" : "peedup",pctint / 100,pctint % 100);
  195.         if    (has010)
  196.             Printf(" (%s predicted)"," 23.00");
  197.         Printf("\n");
  198.     }
  199.     CloseDevice((struct IORequest *)treq);
  200.     DeleteExtIO((struct IORequest *)treq);
  201.     DeletePort(tport);
  202.     return 0;
  203. }
  204.  
  205. #asm
  206.     xdef    _donaught
  207.     xdef    __cli_parse
  208.     xdef    __wb_parse
  209. _donaught:
  210. __cli_parse:
  211. __wb_parse:
  212.     rts
  213. #endasm
  214.  
  215. void testit(unsigned long loops,unsigned long bytes,long offset)
  216. {
  217.     struct timeval    *time1 = &tim1,
  218.             *time2 = &tim2,
  219.             *time3 = &tim3;
  220.     unsigned long    pctint;
  221.  
  222.     Printf("Copying %ld bytes %ld times (",bytes,loops);
  223.     buf3 = buf1;
  224.     buf4 = buf2;
  225.     switch(offset)
  226.     {
  227.         case O_LONG:    Printf("long");
  228.                 break;
  229.         case O_EVEN:    Printf("even");
  230.                 buf3 += 2;
  231.                 buf4 += 2;
  232.                 break;
  233.         case O_ODD:    Printf("odd");
  234.                 buf3 += 3;
  235.                 break;
  236.     }
  237.     Printf(" offset)\n");
  238.  
  239.     GetSysTime(time1);
  240.     Forbid();
  241.     {
  242. #asm
  243.     movem.l    a2-a3/a6/d4-d5,-(sp)
  244.     movea.l    _naught,a2
  245.     movea.l    _buf3,a3
  246.     movea.l    _buf4,a6
  247.     move.l    %%loops,d4
  248.     move.w    d4,d5
  249.     swap    d4
  250.     subq.w    #1,d5
  251.     bcs.s    l1end
  252. loop1    movea.l    a3,a0
  253.     movea.l    a6,a1
  254.     move.l    %%bytes,d0
  255.     jsr    (a2)
  256.     dbf    d5,loop1
  257. l1end    dbf    d4,loop1
  258.     movem.l    (sp)+,a2-a3/a6/d4-d5
  259. #endasm
  260.     }
  261.     Permit();
  262.     GetSysTime(time3);
  263.     SubTime(time3,time1);
  264.     GetSysTime(time1);
  265.     Forbid();
  266.     {
  267. #asm
  268.     movem.l    a2-a3/a6/d4-d5,-(sp)
  269.     movea.l    _oldcms,a2
  270.     movea.l    _buf3,a3
  271.     movea.l    _buf4,a6
  272.     move.l    %%loops,d4
  273.     move.w    d4,d5
  274.     swap    d4
  275.     subq.w    #1,d5
  276.     bcs.s    l2end
  277. loop2    movea.l    a3,a0
  278.     movea.l    a6,a1
  279.     move.l    %%bytes,d0
  280.     jsr    (a2)
  281.     dbf    d5,loop2
  282. l2end    dbf    d4,loop2
  283.     movem.l    (sp)+,a2-a3/a6/d4-d5
  284. #endasm
  285.     }
  286.     Permit();
  287.     GetSysTime(time2);
  288.     SubTime(time2,time1);
  289.     SubTime(time2,time3);
  290.     AddTime(&totold,time2);
  291.     timold.tv_secs = 
  292.     timdif.tv_secs = time2->tv_secs;
  293.     timold.tv_micro =
  294.     timdif.tv_micro = time2->tv_micro;
  295.     Printf("Old CopyMem%s: %2ld.%02ld secs\n","\t",time2->tv_secs,time2->tv_micro / 10000);
  296.  
  297.     GetSysTime(time1);
  298.     Forbid();
  299.     {
  300. #asm
  301.     movem.l    a2-a3/a6/d4-d5,-(sp)
  302.     movea.l    _newcms,a2
  303.     movea.l    _buf3,a3
  304.     movea.l    _buf4,a6
  305.     move.l    %%loops,d4
  306.     move.w    d4,d5
  307.     swap    d4
  308.     subq.w    #1,d5
  309.     bcs.s    l3end
  310. loop3    movea.l    a3,a0
  311.     movea.l    a6,a1
  312.     move.l    %%bytes,d0
  313.     jsr    (a2)
  314.     dbf    d5,loop3
  315. l3end    dbf    d4,loop3
  316.     movem.l    (sp)+,a2-a3/a6/d4-d5
  317. #endasm
  318.     }
  319.     Permit();
  320.     GetSysTime(time2);
  321.     SubTime(time2,time1);
  322.     SubTime(time2,time3);
  323.     AddTime(&totnew,time2);
  324.     SubTime(&timdif,time2);
  325.     if    ((LONG)timdif.tv_secs < 0)
  326.     {
  327.         timdif.tv_secs = -((LONG)timdif.tv_secs + 1);
  328.         timdif.tv_micro = 1000000 - timdif.tv_micro;
  329.         negative = TRUE;
  330.     }
  331.     else    negative = FALSE;
  332.     Printf("New CopyMem%s: %2ld.%02ld secs","\t",time2->tv_secs,time2->tv_micro / 10000);
  333.     pctint    = ((timdif.tv_secs * 100) + (timdif.tv_micro / 10000)) * 10000
  334.         / ((timold.tv_secs * 100) + (timold.tv_micro / 10000));
  335.     if    ((pctint % 10) > 5)
  336.         pctint += 10;
  337.     pctint /= 10;
  338.     Printf(" (%s%2ld.%ld%%)\n",(negative) ? "+" : "-",pctint / 10,pctint % 10);
  339.     if    ((!offset) && (!(bytes % 4)))
  340.     {
  341.     GetSysTime(time1);
  342.     Forbid();
  343.     {
  344. #asm
  345.     movem.l    a2-a3/a6/d4-d5,-(sp)
  346.     movea.l    _oldcmq,a2
  347.     movea.l    _buf3,a3
  348.     movea.l    _buf4,a6
  349.     move.l    %%loops,d4
  350.     move.w    d4,d5
  351.     swap    d4
  352.     subq.w    #1,d5
  353.     bcs.s    l4end
  354. loop4    movea.l    a3,a0
  355.     movea.l    a6,a1
  356.     move.l    %%bytes,d0
  357.     jsr    (a2)
  358.     dbf    d5,loop4
  359. l4end    dbf    d4,loop4
  360.     movem.l    (sp)+,a2-a3/a6/d4-d5
  361. #endasm
  362.     }
  363.     Permit();
  364.     GetSysTime(time2);
  365.     SubTime(time2,time1);
  366.     SubTime(time2,time3);
  367.     AddTime(&totold,time2);
  368.     timold.tv_secs = 
  369.     timdif.tv_secs = time2->tv_secs;
  370.     timold.tv_micro =
  371.     timdif.tv_micro = time2->tv_micro;
  372.     Printf("Old CopyMem%s: %2ld.%02ld secs\n","Quick",time2->tv_secs,time2->tv_micro / 10000);
  373.  
  374.     GetSysTime(time1);
  375.     Forbid();
  376.     {
  377. #asm
  378.     movem.l    a2-a3/a6/d4-d5,-(sp)
  379.     movea.l    _newcmq,a2
  380.     movea.l    _buf3,a3
  381.     movea.l    _buf4,a6
  382.     move.l    %%loops,d4
  383.     move.w    d4,d5
  384.     swap    d4
  385.     subq.w    #1,d5
  386.     bcs.s    l5end
  387. loop5    movea.l    a3,a0
  388.     movea.l    a6,a1
  389.     move.l    %%bytes,d0
  390.     jsr    (a2)
  391.     dbf    d5,loop5
  392. l5end    dbf    d4,loop5
  393.     movem.l    (sp)+,a2-a3/a6/d4-d5
  394. #endasm
  395.     }
  396.     Permit();
  397.     GetSysTime(time2);
  398.     SubTime(time2,time1);
  399.     SubTime(time2,time3);
  400.     AddTime(&totnew,time2);
  401.     SubTime(&timdif,time2);
  402.     if    ((LONG)timdif.tv_secs < 0)
  403.     {
  404.         timdif.tv_secs = -((LONG)timdif.tv_secs + 1);
  405.         timdif.tv_micro = 1000000 - timdif.tv_micro;
  406.         negative = TRUE;
  407.     }
  408.     else    negative = FALSE;
  409.     Printf("New CopyMem%s: %2ld.%02ld secs","Quick",time2->tv_secs,time2->tv_micro / 10000);
  410.     pctint    = ((timdif.tv_secs * 100) + (timdif.tv_micro / 10000)) * 10000
  411.         / ((timold.tv_secs * 100) + (timold.tv_micro / 10000));
  412.     if    ((pctint % 10) > 5)
  413.         pctint += 10;
  414.     pctint /= 10;
  415.     Printf(" (%s%2ld.%ld%%)\n",(negative) ? "+" : "-",pctint / 10,pctint % 10);
  416.     }
  417.     Printf("\n");
  418. }
  419.  
  420.