seive.tst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. 27-Mar-83 09:09:18-MST,4778;000000000001
  2. Return-path: <GRISS@HP-HULK>
  3. Received: from UTAH-CS by UTAH-20; Sun 27 Mar 83 09:07:41-MST
  4. Date: 27 Mar 1983 0753-PST
  5. From: GRISS@HP-HULK
  6. Subject: String and vector
  7. Message-Id: <417628520.17208.hplabs@HP-VENUS>
  8. Received: by HP-VENUS via CHAOSNET; 27 Mar 1983 07:55:19-PST
  9. Received: by UTAH-CS.ARPA (3.320.3/3.7.4)
  10. id AA28476; 27 Mar 83 08:59:13 MST (Sun)
  11. To: kessler@HP-VENUS, griss@HP-VENUS
  12. I was doing some timings on SIEVE.RED (attached) on VAX and 20.
  13. Havent yet done for 68000. Compared with C on VAX:
  14. a) Proportionately, VECTOR much slower on VAX; due to need to multiply
  15. by 4 to convert VECITM(V,i)=> V+4*(i+1) on VAX; if I work with P4=4*P,
  16. (CheatVtest), am getting code about as fast as C on the VAX for Vectors.
  17. b) On VAX, string pointer of course just byte address, while on 20 have to
  18. unpack bytes, using LDB and ADJBP, so that STRING much slower than
  19. even on VAX!
  20. 26 March, tests of SIEVE.C and SIEVE.RED on MARS, vax-790
  21. ---------------------------------------------------------
  22. 100 loops of sieve of Eratosthenes, on 1000 length sieve.
  23. This is a set of LOOPs with no procedure calls (in C or SYSLISP).
  24. Test C Fast C PSL SYSLISP SYSLISP/fast C
  25. STRING 3264 2941 66130 3519 1.2
  26. VECTOR 3077 2720 26520 4284 (a) 1.6
  27. On DEC-20, String 33970 5970 (b)
  28. Vector 11370 1896 (c)
  29. Notes:
  30. (a) on VAX, use 4*index as pointer, get 2618, and code similar to C.
  31. (b) notice that this slower than VAX, since using LDB and ADJBP on 20
  32. but direct BYTE address on VAX.
  33. (c) on 20, if we use pointer rather than index, get 1541 which is not as
  34. dramatic as on the VAx, since not saving the 4* to convert index
  35. to BYTE address
  36. (d) Fast-C uses the -O code improvment option, and some loops seem to use
  37. a AOBLEQ (on VAX, like AOBJN on 20).
  38. May want to start thinking about Code-Gen improvments, and source to
  39. source improvements to catch these and similar constructs. Discuss
  40. with Mark, Jed, Bobbie
  41. % sieve.red -----
  42. on comp;
  43. Fluid '(Tim1 Tim2);
  44. on syslisp;
  45. procedure start();
  46. Lispvar(tim1) :=timc();
  47. procedure done s;
  48. <<lispvar(tim2):=timc();
  49. printf(" ---- %p ---%p%n",s,lispvar(tim2)-lispvar(tim1));
  50. >>;
  51. procedure TestSL n;
  52. begin scalar primes;
  53. primes := Mkstring(1000,1);
  54. start();
  55. for i:=1:n do Lsieve primes;
  56. done "lsieve, string";
  57. end;
  58. procedure TestVL n;
  59. begin scalar primes;
  60. primes := MkVect(1000);
  61. start();
  62. for i:=1:n do Lsieve primes;
  63. done "lsieve, vector";
  64. end;
  65. procedure TestV n;
  66. begin scalar primes;
  67. primes := Mkvect 1000;
  68. start();
  69. for i:=1:n do Vsieve primes;
  70. done "Vsieve";
  71. end;
  72. procedure TestCheatV n;
  73. begin scalar primes;
  74. primes := Mkvect 1000;
  75. start();
  76. for i:=1:n do CheatVsieve primes;
  77. done "CheatVsieve";
  78. end;
  79. procedure TestS n;
  80. begin scalar primes;
  81. primes := Mkstring(1000,1);
  82. start();
  83. for i:=1:n do Ssieve primes;
  84. done "Ssieve";
  85. end;
  86. off syslisp;
  87. lisp procedure lsieve(primes);
  88. begin
  89. scalar p, mp;
  90. for i:=0:1000 do setindx(primes,1);
  91. % printf("Primes%n");
  92. for p := 2:1000 do
  93. if indx(primes, p) eq 1 then
  94. <<
  95. % printf(" %d%n", p);
  96. for mp := 2*p step p until 1000 do
  97. setindx(primes, mp, 0)
  98. >>
  99. end;
  100. on syslisp;
  101. syslisp procedure ssieve(primes);
  102. begin
  103. scalar p, mp;
  104. primes := strinf primes;
  105. for i:=0:1000 do strbyt(primes,i):=1;
  106. % printf("Primes%n");
  107. for p := 2:1000 do
  108. if strbyt(primes, p) eq 1 then
  109. <<
  110. % printf(" %d%n", p);
  111. for mp := 2*p step p until 1000 do
  112. strbyt(primes, mp) := 0
  113. >>
  114. end;
  115. syslisp procedure vsieve(primes);
  116. begin
  117. scalar p, mp;
  118. primes := vecinf(primes);
  119. for p:=0:1000 do vecitm(vecinf primes,p):=1;
  120. % printf("Primes%n");
  121. for p := 2:1000 do
  122. if vecitm(primes, p) eq 1 then
  123. <<
  124. % printf(" %d%n", p);
  125. for mp := 2*p step p until 1000 do
  126. vecitm(primes, mp) := 0
  127. >>
  128. end;
  129. syslisp procedure Cheatvsieve(primes);
  130. begin
  131. scalar p, p4, mp,mp4, base;
  132. primes := vecinf(primes);
  133. base := primes +addressingunitsperitem;
  134. p4:= base +0;
  135. for p:=0:1000 do <<putmem(p4,1); p4:=p4+addressingunitsperitem>>;
  136. % printf("Primes%n");
  137. p4:=base+2*addressingunitsperitem;
  138. for p := 2:1000 do
  139. << if getmem( p4) eq 1 then
  140. <<
  141. % printf(" %d%n", p);
  142. mp4 := base +2*addressingunitsperitem*p;
  143. for mp := 2*p step p until 1000 do
  144. <<putmem(mp4,0); mp4:=mp4+addressingunitsperitem >> >>;
  145. p4 :=p4 +addressingunitsperitem>>
  146. end;
  147. off syslisp;
  148. end;
  149. -------