Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
For the out-of-band Slashdot experience (mostly headlines), follow us on Twitter, or Facebook. ×

Comment: Re:Check their work or check the summary? (Score 1) 486 486

OMG C is SOOOooOO slow compared to my l33t Java code! In the spirit of the fine paper related to this article, here's a 100% fair, unbiased comparison of both languages.
[code lang="c"]
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char** argv) {
    const char* appendString = "1";

    char* concatString = (char*)malloc(1);
    concatString[0] = 0;

    int numIter = 100000;

    clock_t startTime, endTime;

    startTime = clock();

    for (int i = 0; i < numIter; i++) {
        char* tempString = (char*)malloc(strlen(concatString) + strlen(appendString) + 1);
        strcpy(tempString, concatString);
        strcat(tempString, appendString);
        free(concatString);
        concatString = tempString;
    }

    endTime = clock();

    double totalTime = (double)(endTime - startTime) / CLOCKS_PER_SEC;
    printf("Operation took %f seconds", totalTime);
    return EXIT_SUCCESS;
}
[/code]

[code lang="java"]
public class Crap {
    public static void main(String[] args) {
        String appendString = "1";
        String concatString = "";

        int numIter = 100000;

        long startTime, endTime;

        startTime = System.currentTimeMillis();

        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < numIter; i++) {
            builder.append(appendString);
        }

        concatString = builder.toString();
        endTime = System.currentTimeMillis();
        double totalTime = (double)(endTime - startTime) / 1000;

        System.out.printf("Operation took %f seconds\n", totalTime);

    }
}
[/code]

[code lang="term"]
$ cc -O3 crap.c -o crap
$ ./crap
Operation took 0.749926 seconds
$ javac Crap.java
$ java Crap
Operation took 0,009000 seconds
[/code]

Look how FATSTER JAVA is compared to C!!!!1!! You should be ashamed of using such a sloow programming language like C!

We have a equal opportunity Calculus class -- it's fully integrated.

Working...