Re: prefixes and namespaces?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Bernie Ryan wrote:
> 
>    Where did map come from ?

yuku
 
>    It is not in the archive.
>    
>    I don't see.
> 
>    Why aren't you using Associative Lists (Tables) by Jiri Babor
>    who is a master at writing fast precise code.  

Because map is simpler, a cleaner interface and a little more than 3 times
faster.

tables:
include stables.e

integer n
sequence t
object v

n = 10000
t = ET

for i = 1 to n do
    t = insert(t, sprintf("key%d", {i}), sprintf("value%d", {i}))
end for

for i = 1 to n do
    v = fetch(t, sprintf("key%d", {i}))
    if equal(v, sprintf("value%d", {i})) = 0 then
        puts(1, "Invalid find\n")
        abort(1)
    end if
end for


map:
include map.e

integer n
object v
map m

n = 10000
m = map_new()

for i = 1 to n do
    m = map_put(m, sprintf("key%d", {i}), sprintf("value%d", {i}))
end for

for i = 1 to n do
    v = map_get(m, sprintf("key%d", {i}), 0)
    if equal(v, sprintf("value%d", {i})) = 0 then
        puts(1, "Invalid find\n")
        abort(1)
    end if
end for


Timing:

$ time exu benchmap.exu 

real    0m0.266s
user    0m0.267s
sys     0m0.000s

$ time exu benchother.exu 

real    0m0.886s
user    0m0.880s
sys     0m0.007s

I ran the above 2 commands 10 times each. All results were within 0.005s of
themselves. stable was the fastest of the three. tables took 2.203s to complete
the same test.

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu