Re: (severe) performance issues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi David,

On 3/26/07, David J. Andruczyk <djandruczyk@xxxxxxxxx> wrote:
> I would NOT expect updating approx 10 labels perhaps 5-10 times per
> second (ie. when data chages) on a 1.8Ghz machine be so cpu hungry.

I made a tiny test program. This updates 50 labels at 100Hz with less
than 1% CPU on my machine.

--------------
/* compile with
 *      gcc -Wall try16.c `pkg-config gtk+-2.0 --cflags --libs`
 */

#include <gtk/gtk.h>
#include <stdlib.h>

const int NUM_LABELS = 50;
const int FPS = 100;

gboolean
update_labels (GtkWidget * label[])
{
  int i;

  for (i = 0; i < NUM_LABELS; i++)
    {
      char buf[256];

      snprintf (buf, 256, "%d", rand ());
      gtk_label_set_text (GTK_LABEL (label[i]), buf);
    }

  return TRUE;
}

int
main (int argc, char **argv)
{
  GtkWidget *label[NUM_LABELS];
  GtkWidget *win, *box;
  int i;

  gtk_init (&argc, &argv);
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (win, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  box = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (win), box);

  for (i = 0; i < NUM_LABELS; i++)
    {
      label[i] = gtk_label_new (NULL);
      gtk_box_pack_start (GTK_BOX (box), label[i], TRUE, TRUE, 0);
    }

  g_timeout_add (1000 / FPS, (GSourceFunc) update_labels, label);

  gtk_widget_show_all (win);

  gtk_main ();

  return 0;
}
-------------

I have Dapper still on my machine (gtk 2.8, amd64 2.7 GHz) which might
make some difference I guess. Though I think Pango has actually sped
up in 2.10.

I wonder if another reason might be resizing? Setting a label's text
can cause the label to change size, which might be forcing some
(large?) chunk of your interface to resize too. You could try using
gtk_widget_set_size_request() on your labels to make them a fixed
size.

John
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux