On 23/03/07 9:14 AM, Bram Moolenaar wrote:
Ernie Rael wrote:

Is it worth adding a putifabsent(dict, key, value) builtin function?
Discuss among yourselves ;-)

...

"d->extend({k: v})" is the only builtin way (that I know of).
...
I was surprised to see a user function ~1,000 times slower.
Invoking a user function has a lot of overhead.  You did use a compiled
function?
I did. But I was uncomfortable with the results; finally this morning it occurred to me that I wasn't using the profiler correctly for micro benchmarking and I'm looking at that right now. I don't believe the function is 1,000 slower, maybe more like 100 times slower.

The profiling, in micro-sec/op, is of putting a single k,v into a
dictionary; the key is already in the target dictionary, column header
is the number of keys in the target dictionary. There's something
curious going on around 200 keys.
I don't think adding a function specifically to make something a bit
faster is a good idea.
Agreed, that's the conclusion I came to. And for this case, extend looks good and works well, I got started on this because a user function was so slow.
  Using extend() should work, perhaps a little
profiling can show how to make it go faster.
Maybe, at first glance it looks like building the temp dictionary to pass to extend is ~1/3 of the time.
  It might be that looping
over the dictionary to find the one entry adds some overhead (there are
always empty entries in the dictionary to make adding more items fast).

Might take a look (I always enjoy running a profiler :-) )

-ernie




--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/0308cd44-f8c5-a664-d9ad-3c80709332a6%40raelity.com.

Raspunde prin e-mail lui