home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / SMALL_C / BENCH / MOVE88.C < prev    next >
Text File  |  1980-01-01  |  4KB  |  166 lines

  1. /*
  2. ** BYTE Small-C String Move Benchmark
  3. ** Version 1 for 8088/8086/80286
  4. ** March, 1988
  5. ** Written in BYTE Small-C
  6. ** Based on Small-C by J.E. Hendrix
  7. **
  8. ** This benchmark moves strings from on location to another.
  9. ** The strings are moved byte-at-a-time and word-at-a-time.
  10. **
  11. ** Operation:
  12. ** 1. Allocate source and destination buffers.
  13. ** 2. Turn on stopwatch.
  14. ** 3. Move contents of source buffer to destination buffer,
  15. **    COUNT times, byte-at-a-time.
  16. ** 4. Turn off stopwatch.
  17. ** 5. Report results.
  18. ** 6. Modify source and destination buffer pointers to point
  19. **    to odd byte locations.
  20. ** 7. Turn on stopwatch.
  21. ** 8. Move contents of source buffer to destination buffer,
  22. **    COUNT times, word-at-a-time.
  23. ** 9. Turn off stopwatch.
  24. ** 10. Report results.
  25. ** 11. Modify source and destination buffer pointers to point
  26. **     to even byte locations.
  27. ** 12. Turn on stopwatch.
  28. ** 13. Move contents of source buffer to destination buffer,
  29. **     COUNT times, word-at-a-time.
  30. ** 14. Turn off stopwatch.
  31. ** 15. Report results.
  32. ** 16. Free allocated space and exit.
  33. */
  34.  
  35. #include stdio.h
  36.  
  37. #define BUFSIZE    10000        /* Buffer size */
  38. #define COUNT    10000        /* Repetition count */
  39.  
  40. int tblock[4];            /* Timer block */
  41. char *sbbuff;            /* Byte pointer to source buffer */
  42. char *dbbuff;            /* Byte pointer to dest. buffer */
  43. int *swbuff;            /* Integer pointer to source buffer */
  44. int *dwbuff;            /* Integer pointer to dest. buffer */
  45.  
  46. main()
  47. {
  48.  
  49.     /* Announce yourself */
  50.     printf("BYTE Small-C String Move Benchmark\n");
  51.  
  52.  
  53.     /* Now get source and destination buffers */
  54.     sbbuff=malloc(BUFSIZE+4);
  55.     if (sbbuff==NULL) {
  56.         printf("Not enough memory for source buff.\n");
  57.         exit(0);
  58.     }
  59.     swbuff=sbbuff;
  60.  
  61.     dbbuff=malloc(BUFSIZE+4);
  62.     if (dbbuff==NULL) {
  63.         printf("Not enough memory for dest. buff.\n");
  64.         exit(0);
  65.     }
  66.     dwbuff=dbbuff;
  67.  
  68.     /* Do byte-wide move */
  69.     printf("Byte-wide move---\n");
  70.     printf("bytes:%d repetitions:%d\n",BUFSIZE,COUNT);
  71.  
  72.     gtime(tblock);
  73.     lsmovb(sbbuff,dbbuff,BUFSIZE,COUNT);
  74.     calctim(tblock);
  75.  
  76.     printf("Time: %d:%d:%d:%d (HH:MM:SS:1/100ths)\n\n\n",
  77.       tblock[0],tblock[1],tblock[2],tblock[3]);
  78.  
  79.     /* Do word-wide move */
  80.     printf("Word-wide move---\n");
  81.  
  82.     /* Do first move on odd boundaries */
  83.     if((swbuff&1)!=1) swbuff|=1;
  84.     if((dwbuff&1)!=1) dwbuff|=1;
  85.  
  86.     printf("Odd byte boundary\n");
  87.     printf("bytes:%d repetitions:%d\n",BUFSIZE,COUNT);
  88.  
  89.     gtime(tblock);
  90.     lsmovw(swbuff,dwbuff,BUFSIZE/2,COUNT);
  91.     calctim(tblock);
  92.  
  93.     printf("Time: %d:%d:%d:%d (HH:MM:SS:1/100ths)\n\n",
  94.       tblock[0],tblock[1],tblock[2],tblock[3]);
  95.  
  96.     /* Now do even boundaries */
  97.     swbuff^=1;
  98.     dwbuff^=1;
  99.  
  100.     printf("Even byte boundary\n");
  101.     printf("bytes:%d repetitions:%d\n",BUFSIZE,COUNT);
  102.  
  103.     gtime(tblock);
  104.     lsmovw(swbuff,dwbuff,BUFSIZE/2,COUNT);
  105.     calctim(tblock);
  106.  
  107.     printf("Time: %d:%d:%d:%d (HH:MM:SS:1/100ths)\n\n",
  108.       tblock[0],tblock[1],tblock[2],tblock[3]);
  109.  
  110.     /* Free up space we claimed */
  111.     free(dbbuff);
  112.     free(sbbuff);
  113.  
  114.     /* Go home */
  115.     exit(0);
  116. }
  117.  
  118.  
  119. /*
  120. ** lsmovb(src,dest,n,cnt)
  121. ** Moves n bytes from src to dest.  Repeats cnt time.
  122. */
  123. lsmovb(src,dest,n,cnt)
  124. char *src,*dest;
  125. int n,cnt;
  126. {
  127. #asm
  128.     MOV    BP,SP        ;Get pointer to args
  129.     CLD            ;Clear direction
  130.     MOV    DX,2[BP]    ;Repeat count
  131. LSMOVB1:
  132.     MOV    CX,4[BP]    ;Count
  133.     MOV    DI,6[BP]    ;Destination
  134.     MOV    SI,8[BP]    ;Source
  135.     REP    MOVSB        ;Do the move
  136.     DEC    DX        ;Decr. repeat count
  137.     JNZ    LSMOVB1
  138.     XOR    CX,CX        ;For Small C
  139. #endasm
  140. }
  141.  
  142. /*
  143. /*
  144. ** lsmovw(src,dest,n,cnt)
  145. ** Moves n words from src to dest.  Repeats cnt times.
  146. */
  147. lsmovw(src,dest,n,cnt)
  148. int *src,*dest;
  149. int n,cnt;
  150. {
  151. #asm
  152.     MOV    BP,SP        ;Get pointer to args
  153.     CLD            ;Clear direction
  154.     MOV    DX,2[BP]    ;Repeat count
  155. LSMOVW1:
  156.     MOV    CX,4[BP]    ;Count
  157.     MOV    DI,6[BP]    ;Destination
  158.     MOV    SI,8[BP]    ;Source
  159.     REP    MOVSW        ;Do the move
  160.     DEC    DX        ;Decr. repeat count
  161.     JNZ    LSMOVW1
  162.     XOR    CX,CX        ;For Small C
  163. #endasm
  164. }
  165.  
  166.