[REBOL] Small admin/report benchmark Re:
From: lmecir:geocities at: 19-Sep-2000 10:43
Hi Joel,
I didn't succeed to run your benchmark (not enough memory error occurred),
so I modified it a bit:
Rebol []
file: home/passwords.txt
shells: copy make block! 5
countshell: func [sh [string!] /local shr] [
either none? shr: find shells sh [
append shells reduce [sh 1]
][
change shr: next shr 1 + shr/1
]
]
t1: now/time
p: open/read/lines/direct file
while [not error? try [line: first p]] [
countshell any [pick parse/all line ":" 7 "(none)"]
]
foreach [sh n] sort/skip shells 2 [
n: to-string n
while [3 > length? n] [insert n " "]
print [n sh]
]
prin "Time1: " print now/time - t1
close p
The results were:
>> include/mult %smallad.r
Script: "Untitled" (none)
196608 (none)
98304 /bin/bash
16384 /bin/false
16384 /bin/sync
16384 /sbin/halt
16384 /sbin/shutdown
Time1: 0:00:11
Here is my second attempt, which works with the original file:
REBOL []
include %ads.r
file: home/smallad.txt
shells: make-ads
countshell: func [sh [string!] /local shr] [
associate shells sh 1 + associated/or shells sh [0]
]
p: open/read/lines/direct file
while [not error? try [line: first p]] [
countshell any [pick parse/all line ":" 7 "(none)"]
]
shells2: sort to block! first shells
foreach sh shells2 [
n: associated shells sh
n: to-string n
while [3 > length? n] [insert n " "]
print [n sh]
]
close p
The results are:
12 (none)
6 /bin/bash
1 /bin/false
1 /bin/sync
1 /sbin/halt
1 /sbin/shutdown
For the small input file. Problem is, that for the huge file
(%passwords.txt) an error (a GC fault?) occurs. Would anybody have time to
test it?
Regards
Ladislav
Here is %ads.r:
Hi Rebols,
here is my attempt to satisfy those who don't like objects for ADS
implementation,
those, who would like to have the fast searching capability,
those, who would like to store in Any-type Rebol values and
those who want to use only strings for keys.
Rebol [
Title: "ADS"
Name: 'Ads
File: %Ads.r
Author: "Ladislav Mecir"
Email: [lmecir--geocities--com]
Date: 19/September/2000
]
make-ads: does [reduce [make hash! 0 make block! 0]]
associate: function [
ads [block!]
key [string!]
value [any-type!]
] [index] [
either index: find first ads key [
index: index? index
change at second ads index head insert/only copy [] get/any 'value
] [
insert tail first ads key
insert tail second ads get/any 'value
]
ads
]
deassociate: function [
ads [block!]
key [string!]
] [index] [
if index: find first ads key [
index: index? index
remove at first ads index
remove at second ads index
]
ads
]
associated: function [
ads [block!]
key [string!]
/or
or-block [block!]
] [index] [
either index: find first ads key [
return pick second ads index? index
] [
if or [do or-block]
]
]