0

I have C++ app where it does many calculations, but the most of time it needs to execute simple scripts by PyRun_SimpleString() so I'm curious if is there something in Python/C API, what would do faster following tasks:

  1. do simple assignents like x = 0.1 (changing over time)?
  2. execute script storaged in string (maybe something like compile once to run faster)?

For now I do all these tasks by executing PyRun_SimpleString(). In loop performance loss is significatn.

IzZy
  • 364
  • 3
  • 16

1 Answers1

1

As you suspect, there's indeed two parts to running Python code: interpretation and execution. See Py_CompileString and PyEval_EvalCode. But for simple statements like x=0.1, you might even consider modifying locals yourself via PyLong_FromDouble(0.1)

MSalters
  • 173,980
  • 10
  • 155
  • 350