Skip to content

poor performance #2

@pquiring

Description

@pquiring

The purpose of this project was to create something managed like Java/C# but faster. Short anwser : it's slower.

How could C++ be slower than Java? This prompted me to do some performance tests, and generally C++ code is slower than Java. Only C code was faster.

For this simple example, C/C++ code is slightly faster:

    for(int x=0;x<1024;x++) {
      for(int y=0;y<1024;y++) {
        for(int z=0;z<1024;z++) {
          r += x * y + z;
        }
      }
    }

But when I did more object oriented code, Java was faster:

    ArrayList<String> al = new ArrayList<String>();
    for(int x=0;x<1024*32;x++) {
      al.add(new String("--"));
      int cnt = al.size();
      for(int y=0;y<cnt;y++) {
        String e = al.get(y);
        if (e.equals("test")) {
          System.out.println("ok");
        }
      }
    }

Even when I did a simple test with std C++ objects with highest optimization, it was slower than Java.
When I replaced std objects with simple defined objects and even wrote a simple string compare function instead of the C strcmp() function, only then did the C++ code out perform Java.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions