psl-timer.sl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. % PSL-TIMER.SL Source of PSL "spectral" tests
  2. % Compile this file to produce psl-timer.b
  3. % then LAPIN the file "time-psl.sl"
  4. '(
  5. (sstatus translink t)
  6. (declare (localf tak gtak))
  7. (def de (macro (x) (cons 'defun (cdr x))))
  8. (def igreaterp (macro (x) (cons '> (cdr x))))
  9. (def ilessp (macro (x) (cons '< (cdr x))))
  10. (def iadd1 (macro (x) (cons '1+ (cdr x))))
  11. (def isub1 (macro (x) (cons '1- (cdr x))))
  12. (def itimes2 (macro (x) (cons '* (cdr x))))
  13. (allocate 'fixnum 2000)
  14. (allocate 'list 500)
  15. (setq $gcprint t)
  16. (defun time () (* (car (ptime)) 17))
  17. (defun reclaim () (gc))
  18. )
  19. (de TestSetup ()
  20. (progn
  21. (setq TestList (PrepareTest 1000))
  22. (setq TestList2 (PrepareTest 2000))
  23. (MakeLongList)
  24. (setq EvalForm '(setq Foo (cadr '(1 2 3))))))
  25. (de MakeLongList ()
  26. (prog (I)
  27. (setq LongList '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
  28. (setq I 0)
  29. loop
  30. (cond ((igreaterp I 5) (return nil)))
  31. (setq LongList (append LongList LongList))
  32. (setq I (iadd1 I))
  33. (go loop)))
  34. (de PrepareTest (n)
  35. (prog (l i)
  36. (setq i -1 l nil)
  37. top
  38. (cond ((ilessp n i) (return l)))
  39. (setq i (iadd1 i)
  40. l (cons nil l))
  41. (go top)))
  42. (de Cdr1Test (N)
  43. (prog (I L)
  44. (setq I -1)
  45. loop
  46. (setq I (iadd1 I))
  47. (setq L LongList)
  48. (cond ((igreaterp I N) (return nil)))
  49. loop1
  50. (cond ((atom (setq L (cdr L))) (go loop)))
  51. (go loop1)))
  52. (de Cdr2Test (N)
  53. (prog (I L)
  54. (setq I -1)
  55. loop
  56. (setq I (iadd1 I))
  57. (setq L LongList)
  58. (cond ((igreaterp I N) (return nil)))
  59. loop1
  60. (cond ((null (setq L (cdr L))) (go loop)))
  61. (go loop1)))
  62. (de CddrTest (N)
  63. (prog (I L)
  64. (setq I -1)
  65. loop
  66. (setq I (iadd1 I))
  67. (setq L LongList)
  68. (cond ((igreaterp I N) (return nil)))
  69. loop1
  70. (cond ((null (setq L (cddr L))) (go loop)))
  71. (go loop1)))
  72. (de ListOnlyCdrTest1 ()
  73. (prog (l1 l2)
  74. (setq l1 TestList)
  75. top
  76. (setq l2 TestList)
  77. again
  78. (cond ((null (setq l2 (cdr l2)))
  79. (cond ((null (setq l1 (cdr l1)))
  80. (return nil))
  81. (t (go top))))
  82. (t (go again)))))
  83. (de ListOnlyCddrTest1 ()
  84. (prog (l1 l2)
  85. (setq l1 TestList2)
  86. top
  87. (setq l2 TestList2)
  88. again
  89. (cond ((null (setq l2 (cddr l2)))
  90. (cond ((null (setq l1 (cddr l1)))
  91. (return nil))
  92. (t (go top))))
  93. (t (go again)))))
  94. (de ListOnlyCdrTest2 ()
  95. (prog (l1 l2)
  96. (setq l1 TestList)
  97. top
  98. (setq l2 TestList)
  99. again
  100. (cond ((atom (setq l2 (cdr l2)))
  101. (cond ((atom (setq l1 (cdr l1)))
  102. (return nil))
  103. (t (go top))))
  104. (t (go again)))))
  105. (de ListOnlyCddrTest2 ()
  106. (prog (l1 l2)
  107. (setq l1 TestList2)
  108. top
  109. (setq l2 TestList2)
  110. again
  111. (cond ((atom (setq l2 (cddr l2)))
  112. (cond ((atom (setq l1 (cddr l1)))
  113. (return nil))
  114. (t (go top))))
  115. (t (go again)))))
  116. (de EmptyTest (N)
  117. (prog (I)
  118. (setq I 0)
  119. loop
  120. (cond ((igreaterp I N) (return nil)))
  121. (setq I (iadd1 I))
  122. (go loop)))
  123. (de SlowEmptyTest (N)
  124. (prog (I)
  125. (setq I 0)
  126. loop
  127. (cond ((greaterp I N) (return nil)))
  128. (setq I (add1 I))
  129. (go loop)))
  130. (de ReverseTest (N)
  131. (prog (I)
  132. (setq I 0)
  133. loop
  134. (cond ((igreaterp I N) (return nil)))
  135. (reverse LongList)
  136. (setq I (iadd1 I))
  137. (go loop)))
  138. (de MyReverse1Test (N)
  139. (prog (I)
  140. (setq I 0)
  141. loop
  142. (cond ((igreaterp I N) (return nil)))
  143. (myreverse1 LongList)
  144. (setq I (iadd1 I))
  145. (go loop)))
  146. (de myreverse1 (L)
  147. (prog (M)
  148. loop
  149. (cond ((atom L) (return M)))
  150. (setq M (cons (car L) M))
  151. (setq L (cdr L))
  152. (go loop)))
  153. (de MyReverse2Test (N)
  154. (prog (I)
  155. (setq I 0)
  156. loop
  157. (cond ((igreaterp I N) (return nil)))
  158. (myreverse2 LongList)
  159. (setq I (iadd1 I))
  160. (go loop)))
  161. (de myreverse2 (L)
  162. (prog (M)
  163. loop
  164. (cond ((null L) (return M)))
  165. (setq M (cons (car L) M))
  166. (setq L (cdr L))
  167. (go loop)))
  168. (de LengthTest (N)
  169. (prog (I)
  170. (setq I 0)
  171. loop
  172. (cond ((igreaterp I N) (return nil)))
  173. (length LongList)
  174. (setq I (iadd1 I))
  175. (go loop)))
  176. (de Fact (N)
  177. (cond ((ilessp N 2) 1) (t (itimes2 N (Fact (isub1 N))))))
  178. (de ArithmeticTest (N)
  179. (prog (I)
  180. (setq I 0)
  181. loop
  182. (cond ((igreaterp I N) (return nil)))
  183. (Fact 9)
  184. (setq I (iadd1 I))
  185. (go loop)))
  186. (de EvalTest (N)
  187. (prog (I)
  188. (setq I 0)
  189. loop
  190. (cond ((igreaterp I N) (return nil)))
  191. (eval EvalForm)
  192. (setq I (iadd1 I))
  193. (go loop)))
  194. (de TimeEval (Form)
  195. (prog (I)
  196. (setq I (time))
  197. (eval Form)
  198. (return (difference (time) I))))
  199. (de topleveltak (x y z) (tak x y z))
  200. (de tak (x y z)
  201. (cond ((null (ilessp y x)) z)
  202. (t (tak (tak (isub1 x) y z)
  203. (tak (isub1 y) z x)
  204. (tak (isub1 z) x y)))))
  205. (de toplevelgtak (x y z) (gtak x y z))
  206. (de gtak (x y z)
  207. (cond ((null (lessp y x)) z)
  208. (t (gtak (gtak (sub1 x) y z)
  209. (gtak (sub1 y) z x)
  210. (gtak (sub1 z) x y)))))
  211. (de gtsta (F)
  212. (prog (I)
  213. (setq I 1)
  214. Loop
  215. (cond ((igreaterp I 100000) (return nil)))
  216. (apply F (list I))
  217. (setq I (iadd1 I))
  218. (go Loop)))
  219. (de gtstb (F)
  220. (prog (I)
  221. (setq I 1)
  222. Loop
  223. (cond ((igreaterp I 100000) (return nil)))
  224. (funcall F I)
  225. (setq I (iadd1 I))
  226. (go Loop)))
  227. (de g0 (X) X)
  228. (de g1 (X) (iadd1 X))
  229. (de nreverse (x)
  230. (nreconc x nil))
  231. (de nreconc (x y)
  232. (prog (z)
  233. L (cond ((atom x) (return y)))
  234. (setq z x)
  235. (setq x (cdr x))
  236. (setq y (rplacd z y))
  237. (go L)))
  238. (de nnils (N)
  239. (prog (LST i)
  240. (setq i 0)
  241. loop
  242. (cond ((igreaterp i N) (return LST)))
  243. (setq LST (cons nil LST))
  244. (setq i (iadd1 i))
  245. (go loop)))
  246. (global '(TestGlobalVar))
  247. (de nils (N)
  248. (setq TESTGLOBALVAR (nnils N))
  249. N)
  250. (de nr ()
  251. (setq TESTGLOBALVAR (nreverse TESTGLOBALVAR))
  252. nil)