Try JIT compilation for the NLP and increase optimization level to O3 as seen [here](https://github.com/casadi/casadi/blob/master/docs/examples/python/nlp_codegen.py). Also use `subprocess` instead of `os.system`.