No, it's really "inserting" in mappings and multiset, I guess... *edits the tests*
Gosh, that was *slow*. It seem that even if I have the only other reference (except the expression), it must copy the mapping/multiset:
mapping v=([]); for (int j=0; j<1000; j++) v|=([j:42]);
takes 290ms (repeated 10 times in the test below):
test total user mem (runs) Append array............... 0.760s 0.535s 3524kb (2) (934579/s) Append mapping............. 3.423s 2.910s 3632kb (2) (3436/s) Append multiset............ 0.712s 0.495s 3556kb (2) (20202/s) Insert in mapping.......... 0.701s 0.435s 3800kb (2) (1149425/s) Insert in multiset......... 1.101s 0.820s 3696kb (2) (609756/s)
Note that Append array and the Insert tests enlarges the mapping until it's 100000 elements, while the Append mapping and multiset only manages 1000 elements (already at 10000 it took way too long).
/ Mirar
Previous text:
2003-01-29 09:18: Subject: Re: reasons why pike is better than python?
In the last episode (Jan 29), Mirar @ Pike developers forum said:
a = a[1..]; a += ({ some_value });
^^^^^^^^^^
*removing* elements isn't fast. Adding elements are.
But anyway, I wrote a benchmark for it. It uses v+=({17}) and v[x]=y respectively, up to 100000 elements (k times):
test total user mem (runs) Append array............... 0.808s 0.525s 3540kb (19) (952859/s) Append mapping............. 0.703s 0.459s 3784kb (22) (1090188/s) Append multiset............ 1.132s 0.806s 3684kb (14) (620018/s)
You're not really appending a mapping though; you're inserting a value. What's the benchmark time for doing v+=([ x:y ]) ? It's too bad there isn't an "append array element" syntax that doesn't require you to generate a 1-element array to append.
-- Dan Nelson dnelson@allantgroup.com
/ Brevbäraren