DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2409
Version: 1.3-feature





Link: http://www.fltk.org/str.php?L2409
Version: 1.3-feature
#include <stdio.h>
#include <sys/time.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
//
// Test how long the Fl_Group::clear() operation takes for 20k widgets -erco
//
struct timeval G_tvstart;
// Start timing an operation
void Start(void) {
    gettimeofday(&G_tvstart, NULL);
}
// Return elapsed time so far in floating point seconds
double Elapsed() {
    struct timeval tvnow;
    gettimeofday(&tvnow, NULL);
    long secoff = ( tvnow.tv_sec < G_tvstart.tv_sec ) ? tvnow.tv_sec : 
G_tvstart.tv_sec;
    long usecs1 = ( tvnow.tv_sec - secoff ) * 1000000 + tvnow.tv_usec;
    long usecs2 = ( G_tvstart.tv_sec - secoff ) * 1000000 + G_tvstart.tv_usec;
    // INHERENT BUG: IF TIME DIFFERENCE IS TOO LARGE, WE'LL SUFFER WRAPAROUND
    return((double)(usecs1 - usecs2) / 1000000.0);
}
void Button_CB(Fl_Widget *w, void *d) {
    void RebuildWindow(Fl_Window*);     // prototype
    Fl_Window *win = (Fl_Window*)d;

    // TIME CLEAR OPERATION
    Start();
    win->clear();
    double clear_elapsed = Elapsed();
    fprintf(stderr, "--- Clear 20k buttons: took %.2F seconds\n", 
clear_elapsed);

    // TIME REBUILD BUTTONS
    Start();
    RebuildWindow(win);
    double rebuild_elapsed = Elapsed();
    fprintf(stderr, "--- Rebuild 20k buttons: took %.2F seconds\n", 
rebuild_elapsed);
}

void RebuildWindow(Fl_Window *win) {
    static int count = 0;

    // BUILD 20K BUTTONS (different color each time)
    win->begin();
    for ( int t=0; t<20000; t++ ) {
        int x = (t / 50) * 30;
        int y = (t % 50) * 30;
        Fl_Button *b = new Fl_Button(x,y,20,20,"X");     // extra button 
outside group tests external focus
        b->color(Fl_Color(count % 7 + 1));
        b->callback(Button_CB, (void*)win);
    }
    win->end();
    win->redraw();

    ++count;
}

int main(int argc, char *argv[]) {
    Fl_Window *win = new Fl_Window(800,800,"Example");
    RebuildWindow(win);
    win->show();
    return(Fl::run());
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to