Last change
on this file since 33353 was
33353,
checked in by evhan, 5 years ago

various import fixes in release/5/* after core library changes

File size:
1.0 KB

Line  

1  (use binarysearch) 

2  (use chicken.random) 

3  

4  ;; fill and search vector 

5  

6  (define count 10000000) 

7  

8  (print "fill vector") 

9  

10  (define seq (makevector count)) 

11  

12  (do ((i 0 (add1 i))) 

13  ((>= i count)) 

14  (vectorset! seq i i)) 

15  

16  (define ((compare x) y) ( x y)) 

17  

18  (print "search vector") 

19  

20  (time 

21  (do ((i 0 (add1 i))) 

22  ((>= i 10000)) 

23  (let ((j (random count))) 

24  (assert (= j (binarysearch seq (compare j))))))) 

25  

26  (print "failing search of vector") 

27  (assert (not (binarysearch seq (compare 3)))) 

28  

29  ;; same for list 

30  

31  (print "search list") 

32  

33  (let ((lst (vector>list seq))) 

34  (time 

35  (do ((i 0 (add1 i))) 

36  ((>= i 10)) 

37  (let ((j (random count))) 

38  (assert (= j (binarysearch lst (compare j))))))) 

39  (print "failing search of list") 

40  (assert (not (binarysearch lst (compare 3))))) 

41  

42  ;; abstract sequence 

43  

44  (define (square x) (* x x)) 

45  

46  (print "search abstract sequence") 

47  (time 

48  (do ((i 0 (add1 i))) 

49  ((>= i 10000)) 

50  (let* ((j (random count)) 

51  (k (square j))) 

52  (assert (= j (binarysearch 

53  count 

54  (lambda (x) ( k (square x))))))))) 

Note: See
TracBrowser
for help on using the repository browser.