2

I am taking part in a tournament that requires the submission of a single python file. The problem requires quite a bit of computation in very little time and any performance gain would be very beneficial.

What I am wondering is, can I utilize C in some way? I know about Cython as well as C extensions but they require more than one file which means they are unusable. Is there a way to execute compiled C from inside python without another file?

1 Answers1

1

You could achieve this in two folds, by first making your own package offering wrappers to your C code, and then publishing it with PyPi:

  • You first write a Python interface in C, I guess you already know how to do it.

  • You can follow this tutorial to publish your package, and then call your package with pip install your-package-name

Keep in mind that this process is quite lengthy, if you are in the middle of a competition I am not sure it would be the best solution, but I guess that if you ask this question you have already done all what you can do to optimize the algorithm part. You could also use one of the high performance libs that exist (numpy, pandas). If you are not even allowed to use pip then there is no way to do it in a single file.

NB: I assume that you are allowed to install packages through the terminal

Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81