98
kaushal
6y

C vs python

Comments
  • 1
    @crapped Prove it
  • 3
    @trickory just use the time command under Linux. The startup time for the Python interpreter will ruin everything for such a simple program.
  • 5
    @crapped thr core message was not about the speed. It was about the simplicity.
  • 1
    For such a simple program, the c-compiler would ruin the time as well.
  • 4
    @LinusCDE compilation time is not included for C programs because C programs are typically used as resulting binary.
  • 3
    @Fast-Nop but then it'd only be fair, if you compare it to the compiled python
  • 1
    @Fast-Nop Yeah, but this aproach is about getting the line written 500 times as fast as possible if you start with nothing (not even the compiled binary).
    In that case python wins.
  • 4
    Only works in Python2. That doesn't work in Python3.
  • 7
    Now that we're talking about speed, i present this change to C version:

    ...
    for(count = 500; count != 0; count--) {
    ...
  • 0
    @FrodoSwaggins GCC will optimise printf with a static string just as well as puts.
  • 2
    @hidingFromBoss since everything but 0 and NULL is "true" in C, you might es well drop the comparison. Unless it gives you some performance boost I'm not aware of.
  • 2
    @Awlex It's nice for clarity, and the performance is the same because the subtraction sets the ZERO flag in the CPU automatically.
  • 2
    @hidingFromBoss and talking of simplicity we could just write:
    int count =500;
    while (count - -)
    ...
    PS: Just realized @Awlex already mentioned this.
  • 1
    @phreakyphoenix Though your solution is even simpler than what I had in mind. Nice.
  • 1
    What is the estimated development time for Python vs C (including debugging/compiling/packaging)? How much is developer salary for either? How much more efficient is C code? Does the code need to change often? How often will the code be run (requests/executions)?

    If you write code that needs to be continuously adjusted, and will be executed by a small amount of people (let's say, data analysis or machine learning) a higher level language like Python wins.

    If you develop a product that needs to be optimized for execution and will be used by the whole world (let's say, a kernel module or a server daemon), a lower level language like C would win.
  • 0
    @phreakyphoenix didn't know we could do that in C. Thanks.

    @Awlex could you write your solution too, if it's different from phreakyphoenix's?
  • 1
    @hidingFromBoss it's actually the same as your but without the comparison. I just love (ab)using this whenever possible
  • 0
    @undervalued0

    Teacher: "Write this 500 times!"
    Student: * Builds an embedded system *
    Teacher:
Add Comment