[Python-Dev] insertdict slower?

Jeremy Hylton jeremy@alum.mit.edu
Thu, 1 Feb 2001 14:04:10 -0500 (EST)


I was curious about what the DictCreation microbenchmark in pybench
was slower (about 15%) with 2.1 than with 2.0.  I ran both with
profiling enabled (-pg, no -O) and see that insertdict is a fair bit
slower in 2.1.  Anyone with dict implementation expertise want to
hazard a guess about this?

The profiler indicates the insertdict() is about 30% slower in 2.1, when
the keys are all ints.  int_hash() isn't any slower, but
dict_ass_sub() is about 50% slower.

Of course, this is a microbenchmark that focuses on one tiny corner of
dictionary usage: creating dictionaries with integer keys.  This may
not be a very useful measure of dictionary performance.

Jeremy

Results for Python 2.0
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 54.55      3.90     3.90      285    13.68    19.25  eval_code2
  6.71      4.38     0.48  4500875     0.00     0.00  lookdict
  5.17      4.75     0.37  3000299     0.00     0.00  dict_dealloc
  5.03      5.11     0.36  4506429     0.00     0.00  PyDict_SetItem
  3.78      5.38     0.27  4500170     0.00     0.00  PyObject_SetItem
  2.94      5.59     0.21  1500670     0.00     0.00  dictresize
  2.80      5.79     0.20  4513037     0.00     0.00  insertdict
  2.52      5.97     0.18  3000333     0.00     0.00  PyDict_New
  2.38      6.14     0.17  4510126     0.00     0.00  PyObject_Hash
  2.38      6.31     0.17  4500459     0.00     0.00  int_hash
  2.24      6.47     0.16  3006844     0.00     0.00  gc_list_append
  2.10      6.62     0.15  4500115     0.00     0.00  dict_ass_sub
  1.68      6.74     0.12  3006759     0.00     0.00  gc_list_remove
  1.68      6.86     0.12  3001745     0.00     0.00  PyObject_Init
  1.26      6.95     0.09  3005413     0.00     0.00  _PyGC_Insert

Results for Python 2.1
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 50.00      3.83     3.83      998     3.84     3.84  eval_code2
  6.40      4.32     0.49  4520965     0.00     0.00  lookdict
  4.70      4.68     0.36  4519083     0.00     0.00  PyDict_SetItem
  4.70      5.04     0.36  3001756     0.00     0.00  dict_dealloc
  4.18      5.36     0.32  4500441     0.00     0.00  PyObject_SetItem
  3.39      5.62     0.26  4531084     0.00     0.00  insertdict
  3.00      5.85     0.23  4500354     0.00     0.00  dict_ass_sub
  2.48      6.04     0.19  4507608     0.00     0.00  int_hash
  2.35      6.22     0.18  4576793     0.00     0.00  PyObject_Hash
  2.22      6.39     0.17  3003590     0.00     0.00  PyObject_Init
  2.22      6.56     0.17  3002045     0.00     0.00  PyDict_New
  2.22      6.73     0.17  1502861     0.00     0.00  dictresize
  1.96      6.88     0.15  3023157     0.00     0.00  gc_list_remove
  1.70      7.01     0.13  3020996     0.00     0.00  _PyGC_Remove
  1.57      7.13     0.12  3023452     0.00     0.00  gc_list_append