See Python C++-SIG thread: "object.attr(object& attrname) proposal"
Started 2008-05-25 by <email address hidden>.
Excerpts:
If char const* is passed to objecjt.attr(), it uses
PyObject_GetAttrStrng() or PyObject_SetAttrStrng(). If object is
passed to objecjt.attr(), it takes the object as a Python string
object and uses PyObject_GetAttr() or PyObject_SetAttr().
If attr() behaves like this, it can be useful when there are lots
of objects which you know have the same attribute name. You can save
time by first making a boost::python::object and passing it to every
object's attr() inside a loop.
I just made a bit of modification to boost:python locally and did a
quick test, like
test 1:
for(int i = 0; i < n; ++i)
{
omain.attr(attrname) = 444; //attrname is a char const*
}
test 2:
for(int i = 0; i < n; ++i)
{
object o = omain.attr(attrname); //attrname is a char const*
}
test 3:
for(int i = 0; i < n; ++i)
{
omain.attr(oaaaa) = 444; //oaaaa is boost::python::object that represents a string
}
test 4:
for(int i = 0; i < n; ++i)
{
object o = omain.attr(oaaaa); //oaaaa is boost::python::object that represents a string
}
and it reasonably reflected the difference between PyObject_*Attr() and PyObject_*AttrString.
test 1 :2783ms
test 2 :2357ms
test 3 :1882ms
test 4 :1267ms
test5: PyObject_SetAttrString(po_main, "aaaa", po_num444);
test6: Py_DECREF(PyObject_GetAttrString(po_main, "aaaa"));
test7: PyObject_SetAttr(po_main, po_aaaa, po_num444);
test8: Py_DECREF(PyObject_GetAttr(po_main, po_aaaa));
(po_ prefixed variables are PyObject*),
all inside each for loop, and the results were
test 5 :2410ms
test 6 :2277ms
test 7 :1629ms
test 8 :1094ms
It's boost 1.35.0, Python 2.5 on linux(gcc4.1.2).
I also did the same test on windows(vs8) and the tendency was not
so different.
[SVN r45918]
Merge in documentation fixes. Apart from the change to optional's documenation
Jamfile, which I included by mistake.
Fixes #1659, #1661, #1684, #1685, 1687, #1690, #1801
I wrote about this at:
http://lists.boost.org/Archives/boost/2008/04/136405.php
Merged revisions 44585-44806 via svnmerge from
https://svn.boost.org/svn/boost/branches/doc
........
r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix broken link to vacpp in bjam docs. Refs #1512
........
r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix broken link to bcpp in bjam docs. Refs #1513
........
r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines
DateTime documentation - Fix a link to the serialization library. Refs #1659
........
r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix some links in interprocess & intrusive. Refs #1661
........
r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix some links in the python docs. Refs #1684.
........
r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines
Work around a quickbook bug which is affecting the python docs. Refs #1684.
........
r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix a broken link in the numeric conversion docs. Refs #1685
........
r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix some links in the optional docs. Refs #1687
........
r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix link to the hash documentation from bimap. Refs #1690
........
r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines
Fix a typo in the format library. Refs #1801
........
r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line
Initialise svnmerge.
........
r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines
Fix the lincense url in shared container iterator documentation.
........
r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines
Fix image link in the mpi documentation.
........
r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines
Fix a typo in the spirit docs.
........
r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines
Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844
........
r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines
Fix another typo in spirit docs.
........
[SVN r44807]