diff options
author | Leandro Augusto Fogolin Pereira <leandro@zorg.(none)> | 2009-01-02 18:13:39 -0200 |
---|---|---|
committer | Leandro Augusto Fogolin Pereira <leandro@zorg.(none)> | 2009-01-02 18:13:39 -0200 |
commit | 1ed9b3b12f9de4bf06b23297e68ec85d83e76cc5 (patch) | |
tree | 043e2ebb7267677b5ef6119c26e66dd2039ccfb2 | |
parent | a62ba151352705ce589855e6596b5a580cfa198f (diff) |
Remove ZLib benchmark; add N-Queens benchmark
-rw-r--r-- | hardinfo2/Makefile.in | 7 | ||||
-rw-r--r-- | hardinfo2/arch/common/nqueens.h | 45 | ||||
-rw-r--r-- | hardinfo2/arch/common/zlib.h | 84 | ||||
-rw-r--r-- | hardinfo2/benchmark.c | 24 | ||||
-rw-r--r-- | hardinfo2/nqueens.c | 35 | ||||
-rw-r--r-- | hardinfo2/nqueens.h | 13 | ||||
-rw-r--r-- | hardinfo2/pixmaps/language.png | bin | 950 -> 1135 bytes | |||
-rw-r--r-- | hardinfo2/pixmaps/nqueens.png | bin | 0 -> 1027 bytes |
8 files changed, 110 insertions, 98 deletions
diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index a7f2ea04..1653e73d 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -9,7 +9,7 @@ CCSLOW = gcc -O0 -g OBJECTS = hardinfo.o shell.o util.o iconcache.o loadgraph.o \ menu.o stock.o callbacks.o expr.o report.o binreloc.o \ vendor.o socket.o syncmanager.o -BENCHMARK_OBJECTS = fbench.o sha1.o blowfish.o md5.o +BENCHMARK_OBJECTS = fbench.o sha1.o blowfish.o md5.o nqueens.o MODULES = computer.so devices.so benchmark.so @@ -62,10 +62,15 @@ deb: dist-clean dpkg-buildpackage -rfakeroot -k${USER} install: all + @echo '[01;34m*** Cleaning up installation...[00m' + rm -rf ${DESTDIR}${LIBDIR}/hardinfo/modules ${DESTDIR}/usr/share/hardinfo/pixmaps + @echo '[01;34m*** Creating directories...[00m' mkdir -p ${DESTDIR}/usr/bin mkdir -p ${DESTDIR}/usr/local mkdir -p ${DESTDIR}/usr/share/applications + + mkdir -p ${DESTDIR}${LIBDIR}/hardinfo/modules mkdir -p ${DESTDIR}/usr/share/hardinfo/pixmaps diff --git a/hardinfo2/arch/common/nqueens.h b/hardinfo2/arch/common/nqueens.h new file mode 100644 index 00000000..2a233722 --- /dev/null +++ b/hardinfo2/arch/common/nqueens.h @@ -0,0 +1,45 @@ +/* + * 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 <nqueens.h> + +static gpointer nqueens_for(unsigned int start, unsigned int end, void *data, GTimer *timer) +{ + unsigned int i; + + for (i = start; i <= end; i++) { + nqueens(0); + } + + return NULL; +} + +static void +benchmark_nqueens(void) +{ + gdouble elapsed = 0; + + shell_view_set_enabled(FALSE); + shell_status_update("Running N-Queens benchmark..."); + + elapsed = benchmark_parallel_for(0, 10, nqueens_for, NULL); + + bench_results[BENCHMARK_NQUEENS] = elapsed; +} + + diff --git a/hardinfo2/arch/common/zlib.h b/hardinfo2/arch/common/zlib.h deleted file mode 100644 index 9a24c62f..00000000 --- a/hardinfo2/arch/common/zlib.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 - */ - -static gpointer -parallel_zlib(unsigned int start, unsigned int end, void *data, GTimer *timer) -{ - GModule *libz; - gint i; - glong srclen = 65536; - - static gulong (*compressBound) (glong srclen) = NULL; - static gint (*compress) (gchar *dst, glong *dstlen, - const gchar *src, glong srclen) = NULL; - - if (!(compress && compressBound)) { - libz = g_module_open("libz", G_MODULE_BIND_LAZY); - if (!libz) { - libz = g_module_open("/usr/lib/libz.so", G_MODULE_BIND_LAZY); - if (!libz) { - g_warning("Cannot load ZLib: %s", g_module_error()); - return NULL; - } - } - - if (!g_module_symbol(libz, "compress", (gpointer) & compress) - || !g_module_symbol(libz, "compressBound", (gpointer) & compressBound)) { - - g_module_close(libz); - return NULL; - } - } - - for (i = start; i <= end; i++) { - gchar *dst; - glong dstlen = compressBound(srclen); - - dst = g_new0(gchar, dstlen); - compress(dst, &dstlen, data, srclen); - g_free(dst); - } - - return NULL; -} - - -static void -benchmark_zlib(void) -{ - gdouble elapsed = 0; - gchar *tmpsrc; - gchar *bdata_path; - - shell_view_set_enabled(FALSE); - - bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); - if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { - g_free(bdata_path); - return; - } - - shell_status_update("Compressing 64MB with default options..."); - - elapsed = benchmark_parallel_for(0, 1000, parallel_zlib, tmpsrc); - - g_free(bdata_path); - g_free(tmpsrc); - - bench_results[BENCHMARK_ZLIB] = 65536.0 / elapsed; -} diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c index 3d6ba1fd..b804a0cb 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/benchmark.c @@ -26,31 +26,31 @@ #include <sys/resource.h> enum { - BENCHMARK_ZLIB, BENCHMARK_FIB, BENCHMARK_CRYPTOHASH, BENCHMARK_BLOWFISH, BENCHMARK_RAYTRACE, + BENCHMARK_NQUEENS, BENCHMARK_N_ENTRIES } Entries; -void scan_zlib(gboolean reload); void scan_raytr(gboolean reload); void scan_bfsh(gboolean reload); void scan_cryptohash(gboolean reload); void scan_fib(gboolean reload); +void scan_nqueens(gboolean reload); -gchar *callback_zlib(); gchar *callback_raytr(); gchar *callback_bfsh(); gchar *callback_fib(); gchar *callback_cryptohash(); +gchar *callback_nqueens(); static ModuleEntry entries[] = { - {"CPU ZLib", "compress.png", callback_zlib, scan_zlib}, {"CPU Fibonacci", "module.png", callback_fib, scan_fib}, {"CPU CryptoHash", "module.png", callback_cryptohash, scan_cryptohash}, {"CPU Blowfish", "blowfish.png", callback_bfsh, scan_bfsh}, + {"CPU N-Queens", "nqueens.png", callback_nqueens, scan_nqueens}, {"FPU Raytracing", "raytrace.png", callback_raytr, scan_raytr}, {NULL} }; @@ -209,15 +209,15 @@ static gchar *benchmark_include_results(gdouble result, static gdouble bench_results[BENCHMARK_N_ENTRIES]; #include <arch/common/fib.h> -#include <arch/common/zlib.h> #include <arch/common/cryptohash.h> #include <arch/common/blowfish.h> #include <arch/common/raytrace.h> +#include <arch/common/nqueens.h> -gchar *callback_zlib() +gchar *callback_nqueens() { - return benchmark_include_results_reverse(bench_results[BENCHMARK_ZLIB], - "CPU ZLib"); + return benchmark_include_results_reverse(bench_results[BENCHMARK_NQUEENS], + "CPU N-Queens"); } gchar *callback_raytr() @@ -252,10 +252,10 @@ gchar *callback_fib() setpriority(PRIO_PROCESS, 0, old_priority); \ } while (0); -void scan_zlib(gboolean reload) +void scan_nqueens(gboolean reload) { SCAN_START(); - RUN_WITH_HIGH_PRIORITY(benchmark_zlib); + RUN_WITH_HIGH_PRIORITY(benchmark_nqueens); SCAN_END(); } @@ -290,15 +290,13 @@ void scan_fib(gboolean reload) const gchar *hi_note_func(gint entry) { switch (entry) { - case BENCHMARK_ZLIB: - return "Results in KiB/second. Higher is better."; - case BENCHMARK_CRYPTOHASH: return "Results in MiB/second. Higher is better."; case BENCHMARK_RAYTRACE: case BENCHMARK_BLOWFISH: case BENCHMARK_FIB: + case BENCHMARK_NQUEENS: return "Results in seconds. Lower is better."; } diff --git a/hardinfo2/nqueens.c b/hardinfo2/nqueens.c new file mode 100644 index 00000000..9d36a82e --- /dev/null +++ b/hardinfo2/nqueens.c @@ -0,0 +1,35 @@ +/* + * N-Queens Problem Solver + * Found somewhere on the Internet; can't remember where. Possibly Wikipedia. + */ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +#define QUEENS 11 + +int row[QUEENS]; + +bool safe(int x, int y) +{ + int i; + for (i = 1; i <= y; i++) + if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i) + return false; + return true; +} + +int nqueens(int y) +{ + int x; + + for (x = 0; x < QUEENS; x++) { + if (safe(row[y - 1] = x, y - 1)) + if (y < QUEENS) + nqueens(y + 1); + else + break; + } + + return 0; +} diff --git a/hardinfo2/nqueens.h b/hardinfo2/nqueens.h new file mode 100644 index 00000000..a4be93f0 --- /dev/null +++ b/hardinfo2/nqueens.h @@ -0,0 +1,13 @@ +/* + * N-Queens Problem Solver + * Found somewhere on the Internet; can't remember where. Possibly Wikipedia. + */ +#ifndef __NQUEENS_H__ +#define __NQUEENS_H__ + +int nqueens(int y); + + +#endif /* __NQUEENS_H__ */ + + diff --git a/hardinfo2/pixmaps/language.png b/hardinfo2/pixmaps/language.png Binary files differindex ed0480b1..495a94bc 100644 --- a/hardinfo2/pixmaps/language.png +++ b/hardinfo2/pixmaps/language.png diff --git a/hardinfo2/pixmaps/nqueens.png b/hardinfo2/pixmaps/nqueens.png Binary files differnew file mode 100644 index 00000000..17499732 --- /dev/null +++ b/hardinfo2/pixmaps/nqueens.png |