alias filetest {
if ($isfile(filetest.txt)) { echo -ag The file filetest.txt already exists! | halt }
if ($fopen(filetest)) { .fclose filetest }
var %max = $iif($1 > 0,$1,1000), %str = $str(x,100)
;; WRITE-part
var %x = %max, %t = $ticks
.fopen -n filetest filetest.txt
while (%x) {
.fwrite -n filetest %str
dec %x
}
.fclose filetest
echo -ag /fwrite with %max lines: $calc($ticks - %t) $+ ms - $calc($calc($ticks - %t) / %max) $+ ms per line
if ($2 != f) {
.remove filetest.txt
var %x = %max, %t = $ticks
while (%x) {
write filetest.txt %str
dec %x
}
echo -ag /write with %max lines: $calc($ticks - %t) $+ ms - $calc($calc($ticks - %t) / %max) $+ ms per line
}
;; READ-part
var %t = $ticks
.fopen filetest filetest.txt
while (!$fopen(filetest).eof) {
noop -qg $fread(filetest)
}
.fclose filetest
echo -ag $ $+ fread with %max lines: $calc($ticks - %t) $+ ms - $calc($calc($ticks - %t) / %max) $+ ms per line
if ($2 != f) {
var %x = %max,%t = $ticks
while (%x) {
noop $read(filetest.txt,%x)
dec %x
}
echo -ag $ $+ read with %max lines: $calc($ticks - %t) $+ ms - $calc($calc($ticks - %t) / %max) $+ ms per line
}
.remove filetest.txt
}
alias hashtest {
if ($hget(hashtest)) { hfree hashtest }
if ($isfile(hashtest.hsh)) { .remove hashtest.hsh }
hmake hashtest 100
var %max = $iif($1 > 0,$1,100000), %str = $str(a,1000)
var %i = %max, %t = $ticks
while (%i) {
hadd hashtest %i %str
dec %i
}
echo -ag added %max items in $calc($ticks - %t) $+ ms
var %t = $ticks
hsave hashtest hashtest.hsh
echo -ag saved %max items in $calc($ticks - %t) $+ ms
hfree hashtest
hmake hashtest
var %t = $ticks
hload hashtest hashtest.hsh
echo -ag loaded %max items in $calc($ticks - %t) $+ ms
hfree hashtest
.remove hahstest.hsh
}