File: qa-dictionary

package info (click to toggle)
newlisp 10.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 6,248 kB
  • sloc: ansic: 33,280; lisp: 4,181; sh: 609; makefile: 215
file content (78 lines) | stat: -rwxr-xr-x 2,413 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env newlisp

; qa-dictionary
; check dictionary creation

;(macro (double X) (+ x x))
;(macro (triple X) (+ x x x))
;(macro (bar X) (+ x x x))


(println)
(println "Testing and benchmarking namespaces")

(set 'N 10000)

(if (main-args 2)
	(set 'N (int (main-args 2))))

; define name-space, force creation, stay in MAIN
(context 'Lex) (context MAIN)

(define (qa-dictionary)
    (set 'data (randomize (sequence 1 N)))
    (set 'ass (map list (map string data) data))
	(println "N of associations: " N)
	(println "number of cells before creating Lex: " (sys-info 0))
    (println "time to aquire from association list: " (set 'ta (time (Lex ass))) " ms")
	(println "time to aquire one entry: " 
		(format "%5.3f" (mul 1000 (div ta N))) (append " " (char  956) "s"))

	(print "time reading and verifying entries ... : ")
	(set 'start (time-of-day))
	(set 'sum 0)
	(dolist (a ass)
		(if (!= (Lex (a 0)) (a 1)) 
			(begin
				(println "Error: " (Lex (a 0)) " != " (a 1))
				(set 'read-error true))))
	(set 'ta (- (time-of-day) start))
	(println ta " ms")
	(println "time to read and verify one entry: "
			(format "%5.3f" (mul 1000 (div ta N))) (append " " (char  956) "s"))

	(set 'start (time-of-day))
	(set 'sum 0)
	(dolist (a ass)
		(Lex (a 0)) )
	(set 'ta (- (time-of-day) start))
	(println "time to only read one entry: "
			(format "%5.3f" (mul 1000 (div ta N))) (append " " (char  956) "s"))

	(println "number of cells after creating Lex: " (sys-info 0))
	(println "N of symbols in Lex: " (set 'ns (length (Lex))))
	(println "time to save to file: " (time (save "Lex.lsp" 'Lex)) " ms")
	(println "time to delete namespace: " (set 'td (time (delete 'Lex))) " ms")
	(println "time to delete one symbol: "
		(format "%5.3f" (mul 1000 (div td ns))) (append " " (char  956) "s"))
	(println "number of cells after deleting Lex: " (sys-info 0))
	(println "time to load namespace: " (time (load "Lex.lsp")) " ms")
	(println "number of cells after loading Lex: " (sys-info 0))
	(println "time to save Lex2: " (time (save "Lex2.lsp" 'Lex)) " ms")
	(println)
	(if (and (not read-error) (= (read-file "Lex.lsp") (read-file "Lex2.lsp")))
		(println ">>>>> Dictionary API tested SUCCESSFUL")
		(println ">>>>> PROBLEM in dictionary API"))
)

(qa-dictionary)
(delete-file "Lex.lsp")
(delete-file "Lex2.lsp")
(delete 'Lex)
(set 'data nil)
(set 'ass nil)
(if (main-args 2) 
    (println (sys-info))
    (exit))