diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-08-10 01:47:09 -0300 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-08-10 01:47:09 -0300 | 
| commit | e70ca0d492e6a55ebde7801589cbd75354b98ae9 (patch) | |
| tree | df9b68c67953c4b543ccc43616489bac7f430f65 /hardinfo2 | |
| parent | dfb59cf076b0544b7ee152f28283c9a6e8afdedd (diff) | |
Add simple GPU benchmark
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/Makefile.in | 8 | ||||
| -rw-r--r-- | hardinfo2/arch/common/drawing.h | 28 | ||||
| -rw-r--r-- | hardinfo2/guibench.c | 264 | ||||
| -rw-r--r-- | hardinfo2/guibench.h | 24 | 
4 files changed, 319 insertions, 5 deletions
| diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index abc7cda7..4a2eca61 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -11,7 +11,7 @@ OBJECTS = hardinfo.o shell.o util.o iconcache.o loadgraph.o  \  		vendor.o socket.o syncmanager.o remote.o xmlrpc-server.o \  		xmlrpc-client.o ssh-conn.o egg-markdown.o markdown-text-view.o \  		help-viewer.o -BENCHMARK_OBJECTS = fbench.o sha1.o blowfish.o md5.o nqueens.o fftbench.o +BENCHMARK_OBJECTS = fbench.o sha1.o blowfish.o md5.o nqueens.o fftbench.o guibench.o  MODULES = computer.so devices.so benchmark.so network.so @@ -79,10 +79,8 @@ install:	all  	install -m 755 ${MODULES} ${DESTDIR}${LIBDIR}/hardinfo/modules  	install -m 644 pixmaps/* ${DESTDIR}/usr/share/hardinfo/pixmaps -	[ -e doc/*.hlp ] && install -m 644 doc/*.hlp \ -			${DESTDIR}/usr/share/hardinfo/doc || true -	[ -e doc/*.png ] && install -m 644 doc/*.png \ -			${DESTDIR}/usr/share/hardinfo/doc || true +	install -m 644 doc/*.hlp ${DESTDIR}/usr/share/hardinfo/doc || true +	install -m 644 doc/*.png ${DESTDIR}/usr/share/hardinfo/doc || true  	install -m 644 benchmark.conf ${DESTDIR}/usr/share/hardinfo  	install -m 644 benchmark.data ${DESTDIR}/usr/share/hardinfo diff --git a/hardinfo2/arch/common/drawing.h b/hardinfo2/arch/common/drawing.h new file mode 100644 index 00000000..4ebfb3b5 --- /dev/null +++ b/hardinfo2/arch/common/drawing.h @@ -0,0 +1,28 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#include "guibench.h" + +static void +benchmark_gui(void) +{ +    shell_view_set_enabled(FALSE); +    shell_status_update("Running drawing benchmark..."); +         +    bench_results[BENCHMARK_GUI] = guibench(); +} diff --git a/hardinfo2/guibench.c b/hardinfo2/guibench.c new file mode 100644 index 00000000..f9375b21 --- /dev/null +++ b/hardinfo2/guibench.c @@ -0,0 +1,264 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2009 Leandro A. F. Pereira <leandro@hardinfo.org> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#include <gtk/gtk.h> + +#define N_ITERATIONS 100000 + +typedef double (*BenchCallback)(GtkWindow *window); + +double test_lines(GtkWindow *window); +double test_shapes(GtkWindow *window); +double test_filled_shapes(GtkWindow *window); +double test_text(GtkWindow *window); + +/* +Results on a AMD Athlon 3200+ (Barton), 1GB RAM, +nVidia Geforce 6200 with nvidia Xorg driver. + +Test                Time           Iter/Sec        +Line Drawing        3.9570     25271.7663  +Shape Drawing       22.2499    4494.4065   +Filled Shape Drawing4.0377     24766.2806  +Text Drawing        59.1565    1690.4309   + +Results are normalized according to these values. +So a value around 1.0 will be similar to this  +computer. +*/ + +static struct { +  BenchCallback callback; +  gchar *title; +  gdouble weight; +} tests[] = { +  { test_lines, "Line Drawing", 25271.77 }, +  { test_shapes, "Shape Drawing", 4494.49 }, +  { test_filled_shapes, "Filled Shape Drawing", 24766.28 }, +  { test_text, "Text Drawing", 1690.43  }, +  { NULL, NULL } +}; + +double test_text(GtkWindow *window) +{ +  GRand *rand; +  GTimer *timer; +  GdkGC *gc; +  double time; +  PangoLayout *layout; +  PangoFontDescription *font; +  GdkWindow *gdk_window = GTK_WIDGET(window)->window; +  int strings; +  gchar *tmp; +   +  gdk_window_clear(gdk_window); +   +  rand = g_rand_new(); +  gc = gdk_gc_new(GDK_DRAWABLE(gdk_window)); +  timer = g_timer_new(); +   +  font = pango_font_description_new(); +  layout = pango_layout_new(gtk_widget_get_pango_context(GTK_WIDGET(window))); +  pango_layout_set_text(layout, "I \342\231\245 HardInfo", -1); +   +  g_timer_start(timer); +  for (strings = N_ITERATIONS; strings >= 0; strings--) { +    int x, y, size; + +    x = g_rand_int_range(rand, 0, 800); +    y = g_rand_int_range(rand, 0, 600); +    size = g_rand_int_range(rand, 1, 96) * PANGO_SCALE; +     +    pango_font_description_set_size(font, size); +    pango_layout_set_font_description(layout, font); +    gdk_draw_layout(GDK_DRAWABLE(gdk_window), gc, x, y, layout); +     +    gdk_rgb_gc_set_foreground(gc, strings << 8); + +    while (gtk_events_pending()) { +      gtk_main_iteration(); +    } +     +  } +  g_timer_stop(timer); +   +  time = g_timer_elapsed(timer, NULL); +   +  g_rand_free(rand); +  gdk_gc_destroy(gc); +  g_timer_destroy(timer); +  g_object_unref(layout); +  pango_font_description_free(font); +   +  return time; +} + +double test_filled_shapes(GtkWindow *window) +{ +  GRand *rand; +  GTimer *timer; +  GdkGC *gc; +  double time; +  GdkWindow *gdk_window = GTK_WIDGET(window)->window; +  int lines; +   +  gdk_window_clear(gdk_window); +   +  rand = g_rand_new(); +  gc = gdk_gc_new(GDK_DRAWABLE(gdk_window)); +  timer = g_timer_new(); +   +  g_timer_start(timer); +  for (lines = N_ITERATIONS; lines >= 0; lines--) { +    int x1, y1; +     +    x1 = g_rand_int_range(rand, 0, 800); +    y1 = g_rand_int_range(rand, 0, 600); +     +    gdk_rgb_gc_set_foreground(gc, lines << 8); + +    gdk_draw_rectangle(GDK_DRAWABLE(gdk_window), gc, TRUE, +                       x1, y1, +                       g_rand_int_range(rand, 0, 400), +                       g_rand_int_range(rand, 0, 300)); + +    while (gtk_events_pending()) { +      gtk_main_iteration(); +    } +  } +  g_timer_stop(timer); +   +  time = g_timer_elapsed(timer, NULL); +   +  g_rand_free(rand); +  gdk_gc_destroy(gc); +  g_timer_destroy(timer); +   +  return time; +} + +double test_shapes(GtkWindow *window) +{ +  GRand *rand; +  GTimer *timer; +  GdkGC *gc; +  double time; +  GdkWindow *gdk_window = GTK_WIDGET(window)->window; +  int lines; +   +  gdk_window_clear(gdk_window); +   +  rand = g_rand_new(); +  gc = gdk_gc_new(GDK_DRAWABLE(gdk_window)); +  timer = g_timer_new(); +   +  g_timer_start(timer); +  for (lines = N_ITERATIONS; lines >= 0; lines--) { +    int x1, y1; +     +    x1 = g_rand_int_range(rand, 0, 800); +    y1 = g_rand_int_range(rand, 0, 600); +     +    gdk_rgb_gc_set_foreground(gc, lines << 8); + +    gdk_draw_rectangle(GDK_DRAWABLE(gdk_window), gc, FALSE, +                       x1, y1, +                       g_rand_int_range(rand, 0, 400), +                       g_rand_int_range(rand, 0, 300)); +    while (gtk_events_pending()) { +      gtk_main_iteration(); +    } +  } +  g_timer_stop(timer); +   +  time = g_timer_elapsed(timer, NULL); +   +  g_rand_free(rand); +  gdk_gc_destroy(gc); +  g_timer_destroy(timer); +   +  return time; +} + +double test_lines(GtkWindow *window) +{ +  GRand *rand; +  GTimer *timer; +  GdkGC *gc; +  double time; +  GdkWindow *gdk_window = GTK_WIDGET(window)->window; +  int lines; +   +  gdk_window_clear(gdk_window); +   +  rand = g_rand_new(); +  gc = gdk_gc_new(GDK_DRAWABLE(gdk_window)); +  timer = g_timer_new(); +   +  g_timer_start(timer); +  for (lines = N_ITERATIONS; lines >= 0; lines--) { +    int x1, y1, x2, y2; +     +    x1 = g_rand_int_range(rand, 0, 800); +    y1 = g_rand_int_range(rand, 0, 600); +    x2 = g_rand_int_range(rand, 0, 800); +    y2 = g_rand_int_range(rand, 0, 600); +     +    gdk_draw_line(GDK_DRAWABLE(gdk_window), gc, x1, y1, x2, y2); +    gdk_rgb_gc_set_foreground(gc, lines << 8); +     +    while (gtk_events_pending()) { +      gtk_main_iteration(); +    } +  } +  g_timer_stop(timer); +   +  time = g_timer_elapsed(timer, NULL); +   +  g_rand_free(rand); +  gdk_gc_destroy(gc); +  g_timer_destroy(timer); +   +  return time; +} + +double guibench(void) +{ +  GtkWidget *window; +  gdouble score = 0.0f; +  gint i; + +  window = gtk_window_new(GTK_WINDOW_TOPLEVEL); +  gtk_widget_set_size_request(window, 800, 600); +  gtk_window_set_title(GTK_WINDOW(window), "guibench"); +   +  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); +  gtk_widget_show(window); + +  for (i = 0; tests[i].title; i++) { +    double time; +     +    gtk_window_set_title(GTK_WINDOW(window), tests[i].title);  +    time = tests[i].callback(GTK_WINDOW(window)); +    score += (N_ITERATIONS / time) / tests[i].weight; +  } +   +  gtk_widget_destroy(window); +   +  return score / i; +} diff --git a/hardinfo2/guibench.h b/hardinfo2/guibench.h new file mode 100644 index 00000000..d24403bc --- /dev/null +++ b/hardinfo2/guibench.h @@ -0,0 +1,24 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2009 Leandro A. F. Pereira <leandro@hardinfo.org> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#ifndef __GUIBENCH_H__ +#define __GUIBENCH_H__ + +double guibench(void); + +#endif	/* __GUIBENCH_H__ */
\ No newline at end of file | 
