Performance of 3.0.3 worse than 2.7.7

ant12 wrote on Wednesday, September 25, 2013:

I just moved from glfw-2.7.7 to glfw-3.0.3. My test application gets 50 FPS under 2.7.7 but only 20 FPS under 3.0.3. I’m running OS X 10.7.5.

// init
glfwOpenWindow(428*2, 240*2, 8,8,8,8,0,0, GLFW_WINDOW);

// tight loop
{
  glClear(GL_COLOR_BUFFER_BIT);
  glPixelZoom(2.0, 2.0);
  glDrawPixels(428, 240, GL_RGBA, GL_UNSIGNED_BYTE, &frame_buf_[0]);
  glfwSwapBuffers();
  if (glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
      break; // user chose to quit
}

Anyone know why this should be and what I can do to improve my app’s performance?

elmindreda wrote on Friday, September 27, 2013:

Use a profiler to find out where the bottleneck lies.

ant12 wrote on Friday, October 04, 2013:

That’s a good idea. I had a quick look with XCode Instruments, but got distracted by the fact that I could no longer build the code shown above on Windows with GLFW 3.0.3 because glfwOpenWindow and glfwGetWindowParam no longer exist. So, how come I can still compile and link under OS X? I’m now confused and will need to investigate.

ant12 wrote on Tuesday, October 08, 2013:

// test2.cpp
#include <GL/glfw.h>
#include <cmath>

int main()
{
    if (glfwInit()) {
        glfwOpenWindow(100, 100, 8,8,8,8,0,0, GLFW_WINDOW);
        glfwTerminate();
    }

    float f = 1.234;
    for (long long i = 0; i < 1000000000; ++i)
        f = floor(f);
    return (int)f;
}

$g++ -O2 -g -I/Projects/glfw-2.7.7/include -o test2 test2.cpp /Projects/glfw-2.7.7/lib/cocoa/libglfw.a -framework Cocoa -framework OpenGL -framework IOKit
$time ./test2
real	0m5.748s
user	0m5.487s
sys	0m0.093s

Result for GLFW 2.7.7 5.5 seconds

// test3.cpp
#include <GLFW/glfw3.h>
#include <cmath>

int main()
{
    if (glfwInit()) {
        glfwCreateWindow(100, 100, "hello", 0, 0);
        glfwTerminate();
    }
    
    float f = 1.234;
    for (long long i = 0; i < 1000000000; ++i)
        f = floor(f);
    return (int)f;
}

$g++ -02  -g -o test3 test3.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
$time ./test3

real	0m10.251s
user	0m10.038s
sys	0m0.043s

Result for GLFW 3.0.3 10 seconds

It seems that linking to 2.7.7 under OS X with the i686-apple-darwin11-llvm-g+±4.2 compiler floorf() is used. Whereas linking to 3.0.3 floor() is used, which takes twice as long. (I used Instruments and can see the different functions being called.) This is the cause of the performance slowdown in my application
after moving to 3.0.3.

Anyone have any suggestions on how to change this? I built both 2.7.7 and 3.0.3 from source. Are there build switches I’m not aware of that may be causing this difference.

ant12 wrote on Saturday, October 12, 2013:

The problem was user error, as you might have expected.

Notice my test2 command line contains “-O2”?

Notice my test3 command line contains “-02”?

Sorry for wasting your time and I’m glad I haven’t in fact found a problem in 3.0.3.

Best wishes!