Hello Antonio,<div><br></div><div>Thank you for the update. I'll try and run a long running capture. Several days worth of ARP packets should be enough to maximize JIT effect I suppose.</div><div>I'll keep you updated.</div>
<div><br></div><div>Regards,</div><div>Sébastien</div><div><br></div><div><br><br><div class="gmail_quote">Le 20 février 2012 12:05, Antonio Cuni <span dir="ltr"><<a href="mailto:anto.cuni@gmail.com">anto.cuni@gmail.com</a>></span> a écrit :<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Sébastien,<br>
<br>
I worked a bit on the pypy implementation of ctypes today, and now it is possible to pass ctypes arrays as parameters without leaving the fast path.<br>
The benchmark is still slower on PyPy, but not as much as before. Here are the results on my machine for running arp.py:<br>
<br>
cpython 2.7.2: 224 ms<br>
pypy-c 1.8: 1059 ms<br>
pypy-c trunk: 696 ms<br>
<br>
so, we are about 50% faster than before, although still slower than CPython.<br>
However, 224 ms is definitely too short for the JIT to warm up, so it would be nice if you could rerun the benchmark with a larger capture file.<br>
<br>
It's not necessary to retranslate pypy: you can just download pypy 1.8 and put the binary inside an updated copy of the mercurial repo (the relevant checkin is 6566e81c76a8).<br>
<br>
thank you!<br>
ciao,<br>
Anto<div class="im"><br>
<br>
On 02/13/2012 01:33 PM, Sébastien Volle wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
Hi all,<br>
<br>
My team is working on a project of fast packet sniffers and I'm comparing<br>
performance between different languages.<br>
So, we came up with a simple ARP sniffer that I ported to Python using ctypes.<br>
<br>
During my investigations, I turned out that using ctypes, PyPy 1.8 is<br>
4x slower than CPython 2.6.5.<br>
After looking at the PyPy buglist, it's seems there are couple open issues<br>
about ctypes so I figured I would ask you guys first before filing a new bug.<br>
<br>
I'm pretty new to ctypes and pypy so I'm not sure I understand what's going.<br>
My program seems to spend a lot of time in ctypes/function.py:_convert_<u></u>args<br>
though, has the following profile trace demonstrates:<br>
<br>
$ pypy -m cProfile -s time arp.py<br>
Packet buffer now at 0x9CCECB2<br>
Capture started<br>
elapsed time : 3983.84ms<br>
Total packets : 35571<br>
packets/s : 8928.81<br>
<br>
7839198 function calls (7838340 primitive calls) in 4.105 seconds<br>
<br>
Ordered by: internal time<br>
<br>
ncalls tottime percall cumtime percall filename:lineno(function)<br>
69876 0.546 0.000 1.584 0.000 function.py:480(_convert_args)<br>
214696 0.256 0.000 0.429 0.000 structure.py:236(_subarray)<br>
1052195 0.206 0.000 0.206 0.000 {isinstance}<br>
632437 0.192 0.000 0.192 0.000 {method 'append' of 'list' objects}<br>
175326 0.187 0.000 0.407 0.000 function.py:350(_call_funcptr)<br>
1 0.173 0.173 4.105 4.105 arp.py:1(<module>)<br>
209628 0.158 0.000 0.587 0.000 primitive.py:272(from_param)<br>
214696 0.149 0.000 0.963 0.000 structure.py:90(__get__)<br>
71144 0.143 0.000 0.198 0.000 structure.py:216(__new__)<br>
106713 0.130 0.000 0.208 0.000 array.py:70(_CData_output)<br>
105450 0.124 0.000 2.281 0.000 function.py:689(__call__)<br>
69876 0.123 0.000 1.943 0.000 function.py:278(__call__)<br>
321412 0.102 0.000 0.102 0.000 {method 'fromaddress' of<br>
'Array' objects}<br>
209628 0.088 0.000 0.811 0.000 function.py:437(_conv_param)<br>
179125 0.083 0.000 0.083 0.000 {method 'fieldaddress' of<br>
'StructureInstance' objects}<br>
69883 <a href="tel:0.080%20%20%20%200.000%20%20%20%200.122%20%20%20%200.000" value="+80001220000" target="_blank">0.080 0.000 0.122 0.000</a> primitive.py:308(__init__)<br>
71142 0.076 0.000 0.320 0.000 structure.py:174(from_address)<br>
105450 0.075 0.000 0.145 0.000 function.py:593(_build_result)<br>
139755 0.072 0.000 0.120 0.000<br>
primitive.py:64(generic_xxx_p_<u></u>from_param)<br>
107983 0.070 0.000 0.125 0.000 basics.py:60(_CData_output)<br>
209828 0.062 0.000 0.062 0.000 {method 'get' of 'dict' objects}<br>
107986 0.055 0.000 0.055 0.000 {method '__new__' of<br>
'_ctypes.primitive.SimpleType' objects}<br>
71142 0.052 0.000 0.372 0.000 pointer.py:77(getcontents)<br>
35578 0.052 0.000 0.125 0.000 pointer.py:62(__init__)<br>
35576 0.050 0.000 0.062 0.000 pointer.py:83(setcontents)<br>
106713 0.047 0.000 0.047 0.000 {method '__new__' of<br>
'_ctypes.array.ArrayMeta' objects}<br>
139750 0.043 0.000 0.181 0.000 primitive.py:84(from_param_<u></u>void_p)<br>
209625 0.043 0.000 0.691 0.000 basics.py:50(get_ffi_param)<br>
283592/283435 0.041 0.000 0.041 0.000 {len}<br>
71144 0.040 0.000 0.040 0.000 {method '__new__' of<br>
'_ctypes.structure.<u></u>StructOrUnionMeta' objects}<br>
105450 <a href="tel:0.039%20%20%20%200.000%20%20%20%200.039%20%20%20%200.000" value="+390390000" target="_blank">0.039 0.000 0.039 0.000</a> {method 'free_temp_buffers' of<br>
'_ffi.FuncPtr' objects}<br>
176683 0.037 0.000 0.037 0.000 {hasattr}<br>
35571 0.037 0.000 0.423 0.000 pcap.py:89(next)<br>
<br>
<br>
Anyway, I attached my full project to this mail, including a sample pcap<br>
capture file. It requires libpcap to be installed on your system. Run arp.py<br>
to run the sniffer on the included demo.pcap capture file.<br>
I realize I should try and narrow down the issue some more, but I can't really<br>
afford to spend too much time on this right now so hopefully, this will be a<br>
least a bit helpful.<br>
<br>
Thanks!<br>
<br>
Regards,<br>
Sébastien<br>
<br>
<br></div></div><div class="im">
______________________________<u></u>_________________<br>
pypy-dev mailing list<br>
<a href="mailto:pypy-dev@python.org" target="_blank">pypy-dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/pypy-dev" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/pypy-dev</a><br>
</div></blockquote>
<br>
</blockquote></div><br></div>