Hi,
as far as I (!) understand this:
Lists & items are more understandable for those of us *1) that don't come with much theoretical knowledge in informatics or mathematics, maybe also for those not yet spoiled by the cryptic syntax of the traditional lingo (C, RegExp and such atrocities ...).
Arrays, on the other hand, come with brackets and are stored in a not-human-readable form - exactly what above mentioned, more formally educated people, love & rejoice.
*1) "for the rest of us", as Apple claimed, before they started to "think different" ...
Joke aside. I'd expect arrays to become more suitable compared to lists when it's about speed and complexity. For complexity, I have still to find the barrier when working with lists.
For speed, I tried Craigs example:
At first, I had to make a small change to store enough data to get some measurements. A field is just too small. So I load a custom property first:
Code: Select all
repeat 10000000
put any word of "cat dog snail fly hippo" & space after temp
end repeat
set the waste_bin of this stack to temp
Now Craigs code:
Code: Select all
put the millisecs into t1
put the waste_bin of this stack into temp
repeat for each word tWord in temp
add 1 to tWordCount[tWord]
end repeat
put "ARR " & tWordCount["fly"] & " / " & the millisecs - t1 & CR after fld "display"
He had challenged us:
dunbarx wrote:Now do this with any handler of your choice, without using an array. No problem, but not in a single "working" line either.
Hmmm. Let's see if this is possible:
Code: Select all
put the millisecs into t1
put the waste_bin of this stack into temp
repeat for each word MyWord in temp
if myWord <> "fly" then next repeat else add 1 to MyCounter
end repeat
put "LST " & MyCounter & " / " & the millisecs - t1 & CR after fld "display"
For sure, I only count the flies. But why counting hippos if I don't need to ;-)
Result in fld "display" (LC 6.7.10, "obsolete"):
Code: Select all
ARR 2000958 / 2066
ARR 2000958 / 2069
ARR 2000958 / 2029
ARR 2000958 / 2051
ARR 2000958 / 2095
LST 2000958 / 1961
LST 2000958 / 1977
LST 2000958 / 1938
LST 2000958 / 1985
LST 2000958 / 1977
Interesting! The list version is even a tiny bit faster!
The result in LC 9.0 dp1:
Code: Select all
ARR 2000958 / 15955
ARR 2000958 / 15938
ARR 2000958 / 15966
LST 2000958 / 19301
LST 2000958 / 19351
LST 2000958 / 19293
Ouch!
LC 8.1 isn't much better ...
Code: Select all
ARR 2000958 / 13994
ARR 2000958 / 13942
ARR 2000958 / 13990
LST 2000958 / 15057
LST 2000958 / 15011
LST 2000958 / 15197
I "resaved" the stack then in native 8.1 format, and created a new "waste_bin". Took ages! Results was even worse.
Summary: Working with arrays actually is a tiny bit faster in the new LC versions.
I have to admit that I tried to recreate Craigs example (counting all animals) in 1 line, but didn't succeed in a given time & in a desired speed:
needs pre-initialized variables (else the "do" doesn't work), and is boring slow (only slightly faster than the 9.0 dp1 results ...).
Have fun!