From: Barry S. <ba...@ba...> - 2011-11-27 17:24:40
|
On 22 Nov 2011, at 03:39, <las...@si...> <las...@si...> wrote: > Py::Object fib (const Py::Tuple &args){ > args.verify_length(1); > Py::Long res = args[0]; > if (res<=Py::Long(1)) return Py::Long(1); > else{ > Py::Tuple a(1), b(1); a[0]=Py::Long(res-2); b[0]=Py::Long(res-1); > return fib(a)+fib(b); > } > } Following on from what Paul said: Why use Python objects all the time if the goal is speed? You have transliterated the pure Python code into C++ with all the costs that implies and none of Python's optimizations... Of course its slow. Do not use Py::Long when what you want for speed is int. Create one function that computes the fib using pure C++. Then have a second function that drives is from python. That will avoid the costs of translating to and from the python world. Barry |