home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol069 / bench.pas < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  1KB  |  60 lines

  1. (**************************************************
  2. *
  3. *        BENCHMARK PROGRAM
  4. *
  5. *  In the September issue of Byte, there was a article
  6. * that claimed to benchmark 50 high level languages.
  7. * This is the Pascal version they used. I wanted to see
  8. * if I get the same results. So I am typing it in from
  9. * page 182, listing 2. The algorithm is the most in-
  10. * teresting part of it.
  11. *
  12. * Charlie Foster, September 1981
  13. ***************************************************)
  14.  
  15. (*Eratosthenes Sieve Prime number program*)
  16.  
  17. PROGRAM Prime;
  18.  
  19. CONST
  20.     Size = 8190;
  21. VAR
  22.         Flags : ARRAY [0..Size] OF BOOLEAN;
  23.     x,I, Prime, K, Count, Iter : INTEGER;
  24.  
  25. BEGIN
  26.     WRITELN ('10 iterations');
  27.     FOR Iter := 1 TO 10 DO 
  28.       BEGIN
  29.     {initialize everything first}
  30.         Count := 0;
  31.  
  32. {article had= FillChar (Flags, Sizeof (Flags),CHR (TRUE));}
  33. {But it should have had-----}
  34.  
  35.         FOR x := 0 TO Size DO
  36.           Flags [x] := TRUE;
  37.  
  38.         WRITELN ('Everything initialized--OK');                    
  39.  
  40. {back to the article--------}
  41.  
  42.         FOR I := 0 TO Size DO
  43.         IF Flags[I] = TRUE THEN 
  44.           BEGIN
  45.             Prime := I+I+3;    
  46.             K := I+Prime;
  47.             WHILE K <= Size DO
  48.               BEGIN
  49.                 Flags [K] := FALSE;
  50.                 K := K+Prime
  51.               END;
  52.             Count := Count + 1;
  53.                     WRITE (Prime)
  54.             
  55.           END;
  56.     WRITELN  
  57.     END;
  58.       WRITELN;
  59.       WRITELN ('There are ',Count:4,' Primes')
  60. END.