Git Product home page Git Product logo

Comments (9)

gdementen avatar gdementen commented on September 25, 2024 2

I am not the author of Nuitka, but I can say that it is next to impossible to help you with the information you give. You should try progressively trimming down your program. After each simplification, you compare execution times again, and if the Nuitka-compiled version is still slower than the pure Python version, you continue the simplification. Otherwise, you recover what you just simplified and try simplifying differently, so that you pin point exactly what is the problematic code. Repeat until you have something small enough and self-contained to be included as text in the issue as part of completing the entire issue template that you avoided completing so far.

Alternatively, you might be able to find someone to do that for you for a price. I don't know whether @kayhayen (the main author of Nuitka) does this kind of work as part of his commercial offerings (https://nuitka.net/doc/commercial.html).

PS: not all code is supposed to go significantly faster. For example if your code calls a lot of functions from an external library which is already mostly implemented in C (e.g. numpy), it will not go much faster by compiling it using Nuitka. That said, it should probably not go slower, so your issue could be worth investigating nevertheless.

from nuitka.

jsdjfksnv avatar jsdjfksnv commented on September 25, 2024

I am trying to run a big code by using Python and Nuitka.
Run time for the code using python is 13 secs, however with Nuitka it takes about 14-15 secs.
It is expected that the code should run fast with Nuitka.

Please guide me what should be done in this case

from nuitka.

jsdjfksnv avatar jsdjfksnv commented on September 25, 2024

@gdementen Thank you for the information. I can try simplifying the code to check where the problem is exactly, hopefully that works.

I also have another question. My code does call quite a few functions from external library, so if I call those functions through a different file suppose function.py, and include the code in a different file called main.py, then can I run both the file using nuitka? Is it possilbe to do so?
Will that help in running the code faster?

from nuitka.

gdementen avatar gdementen commented on September 25, 2024

You should read the manual. There are many options. Some of them compile everything, including all dependent modules.

from nuitka.

jsdjfksnv avatar jsdjfksnv commented on September 25, 2024

okay, I will go through it. Can you also explain me the use of standalone and clang?

from nuitka.

kayhayen avatar kayhayen commented on September 25, 2024

This is not a personal support thread, sorry. If you have more questions that the manual does not answer, you can create more issues, but if not, I am likely just deleting them.

from nuitka.

jsdjfksnv avatar jsdjfksnv commented on September 25, 2024

Hello, so I did try running a very simple python code with Nuitka.

modules.py

def add(a, b):
return a + b

def subtract(a, b):
return a - b

class Calculator:
def multiply(self, a, b):
return a * b

def divide(self, a, b):
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b

This was the code for modules.py

and

main.py

from modules import add, subtract, Calculator

def main():
x = 10
y = 5

print(f"Addition: {add(x, y)}")
print(f"Subtraction: {subtract(x, y)}")

calc = Calculator()
print(f"Multiplication: {calc.multiply(x, y)}")
print(f"Division: {calc.divide(x, y)}")

if name == "main":
main()

This is the code for main.py

When I compiled it with python3 it took hardly 0.028secs
however with Nuitka it took 4 secs.

Can you please explain what is going wrong? why is nutika taking so long to run? what should be done in this case?

from nuitka.

jsdjfksnv avatar jsdjfksnv commented on September 25, 2024

I tried with both clang and gcc, the time required is almost sane for both

from nuitka.

gdementen avatar gdementen commented on September 25, 2024

I have a hard time believing the compiled executable for that code would take 4 seconds to RUN, so I suppose you misunderstand how both Python and Nuitka work. Python is an interpreted language, so when you execute a .py file, it is not compiled to binary code but rather executed step by step.

On the other hand, when using Nuitka, it is compiled. That compilation step is very expensive (but only needs to happen once) but then execution time is usually lower. So you trade-off compilation time for easier distribution (what most current users of Nuitka care about) and somewhat faster execution time. In short you should compare Python execution time to the Nuitka-created binary execution time, not the time it took Nuitka to create that binary.

Now if the binary is actually taking 4 seconds to execute (not create!), then there might effectively be a problem somewhere (not necessarily in Nuitka -- it might also be your antivirus being annoyingly slow). IF that is the case AND you have confirmed it is not an antivirus problem, feel free to reopen another issue giving all the information asked by the issue template (without the full issue template filled we cannot help you).

@kayhayen In any case, I feel the current issue should be closed.

from nuitka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.