CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    38

    Embedding Python

    Is there an easy way to embed python in C/C++?

    I'm using visual studio 2010, and the performance of the BigInteger library is really slow compared to how python handles large integers. Is there a way to use python just for the mathematical operations, and C/C++ for the rest?
    Last edited by SamstaUK; May 15th, 2012 at 05:02 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Embedding Python

    Quote Originally Posted by SamstaUK
    I'm using visual studio 2010, and the performance of the BigInteger library is really slow compared to how python handles large integers.
    Maybe next time, if rewriting in Python is not applicable, you should just try another C or C++ bignum library instead, e.g., GMP.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Apr 2009
    Posts
    38

    Re: Embedding Python

    How does GMP compare to python in terms of speed? Python can calculate 2 to the power of 100,000 in 1 second, would GMP have the same or better performance?

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Embedding Python

    You would need to test to find out, since it depends on how large are the numbers and what are your compile options. I would venture a guess that the larger the numbers involved, the better GMP will be compared to Python (and I suspect that for sufficiently small integers, Python will win hands down because the implementation would then switch to use native integers whereas GMP isn't designed for that).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    May 2007
    Posts
    811

    Re: Embedding Python

    Quote Originally Posted by SamstaUK View Post
    Is there an easy way to embed python in C/C++?
    Boost Python

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured