Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <Python.h>
  2.  
  3. int main() {
  4.     const char *code =
  5.             "import time\n"
  6.             "st = time.time()\n"
  7.             "\n"
  8.             "a = 0\n"
  9.             "for i in xrange(int(1e6)):\n"
  10.             "   a += 1\n"
  11.             "print time.time() - st\n"
  12.     ;
  13.  
  14.     Py_Initialize();
  15.  
  16.     PyObject *main = PyImport_AddModule("__main__");
  17.     PyObject *global = PyModule_GetDict(main);
  18.  
  19.     PyCodeObject *co = (PyCodeObject*)Py_CompileString(code, "sf", Py_file_input);
  20.  
  21.     if (co) {
  22.         PyEval_EvalCode(co, global, NULL);
  23.     }
  24.     if (PyErr_Occurred()) {
  25.         PyErr_Print();
  26.     }
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement