Python script and C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thuan Seah Tan

    #1

    Python script and C++

    Hi all,

    I am new to python and currently I am working on a traffic simulation
    which I plan to define the various agents using scripting. It's kind of like
    scripting for non-playable character in games. I am thinking of using python
    for this but I am concerned with running time. Is scripting a lot slower
    compared to direct implementation in C++? Does compiling the script help in
    any way? Also, can anyone recommend me a book that covers python in general
    as well as C++ binding? Thanks.


    Thuan Seah Tan


  • nepBabu.cx

    #2
    Re: Python script and C++

    Thuan Seah Tan wrote:
    Hi all,
    >
    I am new to python and currently I am working on a traffic simulation
    which I plan to define the various agents using scripting. It's kind of like
    scripting for non-playable character in games. I am thinking of using python
    for this but I am concerned with running time. Is scripting a lot slower
    compared to direct implementation in C++? Does compiling the script help in
    "Learning Python" is a good book to start learning Python. I don't think
    you'll be better off in C++. If speed is of utmost importance for the
    whole implementation, then I suggest C++ but well coded Python runs
    atleast/near to C++ implementation. Otherwise, you can atleast code the
    speed-savvy part of the implementation in C++. Ofcourse, Python object
    model is based on a virtual machine (called PVM) which accounts for
    slower start-up due to native function call conversion but you'll find
    that learning curve is only a tiny fraction compared to C++. And you'll
    surely love Python. =)
    any way? Also, can anyone recommend me a book that covers python in general
    as well as C++ binding? Thanks.
    "Progamming in Python" is another excellent book that might be of help.
    If you are developing on windows machine then
    http://aspn.activestate.com/ASPN/Python has some helpful recipes.

    C++ bindings in Python are handled by extending python objects and
    manipulating it from C++ codes using the Python headers.

    Also, http://python.org/docs should be a good reference.
    Also Google for "vaults of parnassus" and Fredrik lundh's guide on Python.

    Goodluck!


    --
    thanks,
    nepBabu.cx
    c c
    .-.,;(")
    ..'`~C.-.c =W=

    Comment

    • George Sakkis

      #3
      Re: Python script and C++

      Thuan Seah Tan wrote:
      Hi all,
      >
      I am new to python and currently I am working on a traffic simulation
      which I plan to define the various agents using scripting. It's kind of like
      scripting for non-playable character in games. I am thinking of using python
      for this but I am concerned with running time. Is scripting a lot slower
      compared to direct implementation in C++? Does compiling the script help in
      any way? Also, can anyone recommend me a book that covers python in general
      as well as C++ binding? Thanks.
      Even if pure python turns out to be slow for some critical parts of
      your application, there are quite a few ways to deal with it: psyco,
      pyrex, weave/blitz, ctypes, SWIG, Boost-python, SIP, CXX, SCXX,
      hand-written C extensions and perhaps more. Visit
      http://www.scipy.org/PerformancePython for an example of taking a
      simple pure Python function and boosting it using several different
      tools. Check out the final comparison table first; the pyrex version is
      less than half a second slower than the C++.

      George

      Comment

      • Ravi Teja

        #4
        Re: Python script and C++

        Thuan Seah Tan wrote:
        Hi all,
        >
        I am new to python and currently I am working on a traffic simulation
        which I plan to define the various agents using scripting. It's kind of like
        scripting for non-playable character in games. I am thinking of using python
        for this but I am concerned with running time. Is scripting a lot slower
        compared to direct implementation in C++? Does compiling the script help in
        any way?
        Python is perfectly suitable for this use. Python was in use in video
        games in this way when computers were a lot slower. I doubt that you
        will need to bother compiling the script or see any observable
        enhancement if you do.

        One example I can remember is Kingdom Under Fire (2001).

        Comment

        • Marc 'BlackJack' Rintsch

          #5
          Re: Python script and C++

          In <1164691472.172 783.151290@n67g 2000cwd.googleg roups.com>, Ravi Teja
          wrote:
          > I am new to python and currently I am working on a traffic simulation
          >which I plan to define the various agents using scripting. It's kind of like
          >scripting for non-playable character in games. I am thinking of using python
          >for this but I am concerned with running time. Is scripting a lot slower
          >compared to direct implementation in C++? Does compiling the script help in
          >any way?
          >
          Python is perfectly suitable for this use. Python was in use in video
          games in this way when computers were a lot slower.
          There's a difference between simulations and games. The simulation will
          not always be observed by a human being so it runs as fast as possible.
          In games the speed of NPCs is usually limited to a level the player can
          deal with.

          But I think Python is fine for such a task. The only way to find out if
          it may be to slow is writing a prototype and measure. Maybe it's a good
          idea to design the API for the "NPCs" independent from the language so you
          can also write them in C++ or another scripting language.

          Ciao,
          Marc 'BlackJack' Rintsch

          Comment

          • Jorgen Grahn

            #6
            Re: Python script and C++

            On Tue, 28 Nov 2006 10:12:23 +0100, Marc 'BlackJack' Rintsch <bj_666@gmx.net wrote:
            In <1164691472.172 783.151290@n67g 2000cwd.googleg roups.com>, Ravi Teja
            wrote:
            >
            >> I am new to python and currently I am working on a traffic simulation
            >>which I plan to define the various agents using scripting. It's kind of like
            >>scripting for non-playable character in games. I am thinking of using python
            >>for this but I am concerned with running time. Is scripting a lot slower
            >>compared to direct implementation in C++? Does compiling the script help in
            >>any way?
            >>
            >Python is perfectly suitable for this use. Python was in use in video
            >games in this way when computers were a lot slower.
            >
            There's a difference between simulations and games. The simulation will
            not always be observed by a human being so it runs as fast as possible.
            In games the speed of NPCs is usually limited to a level the player can
            deal with.
            Yeah. Simulation can mean running for a week on the best hardware available,
            with the most optimized code you can come up with. And a week may be
            acceptable, while two weeks are not.
            But I think Python is fine for such a task.
            I am not so sure, but ...
            The only way to find out if
            it may be to slow is writing a prototype and measure.
            .... this is a good approach.
            Maybe it's a good
            idea to design the API for the "NPCs" independent from the language so you
            can also write them in C++ or another scripting language.
            However, if that API requires thousands of calls per second during
            simulation time, it doesn't help speed much, because calling C code from
            Python is a pretty heavy thing in itself. The big win is when you spend a
            lot of uninterrupted CPU time in C code.

            One approach is to write the executive engine in C++ (once again: if needed)
            and the compiler/configuration subsystem -- the thing that generates the
            simulated world -- in Python. That's a perfect place for a flexible,
            high-level language.

            /Jorgen

            --
            // Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
            \X/ snipabacken.dyn dns.org R'lyeh wgah'nagl fhtagn!

            Comment

            Working...