#!/usr/bin/newlisp
#
# hash2 - benchmark
#
# newLISP does not have hashtables but can
# simulate hashes efficient with symbols
#
(context 'Hash1) ; create hash container
(context 'MAIN) ; go back to MAIN context
(context 'Hash2) ; create hash container
(context 'MAIN) ; go back to MAIN context
(set 'n (integer (main-args 2)))
(dotimes (i 10000)
(set (sym (format "foo_%d" i) Hash1) i) )
(dotimes (i n)
(dotree (k Hash1)
(set 'key (sym (name k) Hash2 nil))
(if key
(inc key (eval k))
(set (sym (name k) Hash2) (eval k)))))
(println Hash1:foo_1 " " Hash1:foo_9999 " " Hash2:foo_1 " " Hash2:foo_9999)
(exit)
syntax highlighting with newLISP and syntax.cgi