home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / test / c / memtest < prev    next >
Encoding:
Text File  |  1994-03-08  |  753 b   |  52 lines

  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. static char *s, *d;
  7.  
  8. static void
  9. memtest (void)
  10. {
  11.   register clock_t t;
  12.   register int i;
  13.  
  14.   t = clock ();
  15.   for (i = 0; i < 2048; i++)
  16.     memcpy (d + (rand () & 3), s + (rand () & 3), rand () & 2047);
  17.   t = clock () - t;
  18.  
  19.   printf ("%d.%02d\n", t / CLK_TCK, t % CLK_TCK);
  20. }
  21.  
  22. int
  23. main (int argc, char **argv)
  24. {
  25.   int i, n;
  26.  
  27.   if (argc != 2)
  28.     {
  29.       puts ("usage: memtest ntest");
  30.       exit (1);
  31.     }
  32.  
  33.   n = atoi (argv[1]);
  34.  
  35.   if (!(s = malloc (2048)))
  36.     {
  37.       perror ("malloc()");
  38.       exit (1);
  39.     }
  40.   if (!(d = malloc (2048)))
  41.     {
  42.       perror ("malloc()");
  43.       exit (1);
  44.     }
  45.  
  46.   srand (time (0));
  47.  
  48.   for (i = 0; i < n; i++)
  49.     memtest ();
  50.   return 0;
  51. }
  52.