edward

An extensible POSIX-compatible implementation of the ed(1) text editor

git clone https://git.8pit.net/edward.git

 1(import (edward buffer)
 2        (edward util))
 3
 4(define-bench (buffer-append-single-at-end)
 5  (let ((buffer (make-buffer)))
 6    (repeat
 7      10000
 8      (lambda ()
 9        (buffer-append!
10          buffer
11          (buffer-length buffer)
12          (list (random-string)))))))
13
14(define-bench (buffer-append-multi-at-end)
15  (let ((buffer (make-buffer)))
16    (repeat
17      10000
18      (let ((next-size 1)
19            (max-size 10))
20        (lambda ()
21          (buffer-append!
22            buffer
23            (buffer-length buffer)
24            (generate-list random-string next-size))
25          (set! next-size (modulo (inc next-size) max-size)))))))
26
27(define-bench (buffer-append-single-randomly)
28  (let ((buffer (make-buffer)))
29    (repeat
30      10000
31      (lambda ()
32        (buffer-append!
33          buffer
34          (pseudo-random-integer (buffer-length buffer))
35          (list (random-string)))))))
36
37(define-bench (buffer-remove-from-front)
38  (let ((buffer (make-buffer))
39        (elems 15000))
40    (buffer-append! buffer 0 (generate-list random-string elems))
41    (repeat elems
42      (lambda ()
43        (buffer-remove! buffer 1 1)))))
44
45(define-bench (buffer-remove-from-back)
46  (let ((buffer (make-buffer))
47        (elems 15000))
48    (buffer-append! buffer 0 (generate-list random-string elems))
49    (repeat elems
50            (lambda ()
51              (let ((len (buffer-length buffer)))
52                (buffer-remove! buffer len len))))))
53
54(define-bench (buffer-remove-entire-content)
55  (let ((buffer (make-buffer))
56        (elems 100000))
57    (buffer-append! buffer 0 (generate-list random-string elems))
58    (buffer-remove! buffer 1 elems)))
59
60(define-bench (buffer-join-entire-content)
61  (let ((buffer (make-buffer))
62        (elems 30000))
63    (buffer-append! buffer 0 (generate-list random-string elems))
64    (buffer-join! buffer 1 elems)))