/* * bench - a simplistic benchmarking program * * * Copyright (C) (2002) (Kyle Davis) * * 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; either * version 2 of the License, or (at your option) any later * version. * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include #include #include gchar** data = NULL; void data_load (gulong count){ gchar* i; if (count>0) g_print (" Load::Limiting to %lu URI's\n", count); if (g_file_get_contents ("data", &i, NULL, NULL)){ data = g_strsplit (i, "\n", count); g_free (i); }else{ g_message ("Run \"find / > data\" for us to have something to test against"); exit (0); } } void tree_test (void){ GTree* t = g_tree_new ((GCompareFunc)strcmp); guint i = 0; while (data[i]){ g_tree_insert (t, data[i++], GINT_TO_POINTER(i)); } g_print (" Tree::Lookup\n"); while (i>1){ g_tree_lookup (t, data[--i]); } g_print (" Tree::RLookup\n"); while (data[i]){ g_tree_lookup (t, data[i++]); } g_tree_destroy (t); } void hash_test (void){ GHashTable* h = g_hash_table_new (g_str_hash, g_str_equal); guint i = 0; while (data[i]){ g_hash_table_insert (h, data[i++], GINT_TO_POINTER(i)); } g_print (" Hash::Lookup\n"); while (i>1){ g_hash_table_lookup (h, data[--i]); } g_print (" Hash::RLookup\n"); while (data[i]){ g_hash_table_lookup (h, data[i++]); } g_hash_table_destroy (h); } void list_sort1_test (void){ GList* l = NULL; guint i = 0; g_print (" ListSort1::Insert\n"); while (data[i]){ l = g_list_prepend (l, data[i++]); } g_print (" ListSort1::Sort\n"); l = g_list_sort (l, (GCompareFunc)strcasecmp); g_list_free (l); } void list_sort2_test (void){ GList* l = NULL; guint i = 0; g_print (" ListSort2::InsertSorted\n"); while (data[i]){ l = g_list_insert_sorted (l, data[i++], (GCompareFunc)strcasecmp); } g_list_free (l); } gdouble bench (gchar* desc, GFunc func, gpointer user_data){ GTimer* t = g_timer_new (); gdouble r; g_print ("%s\n", desc); func (user_data, NULL); r = g_timer_elapsed (t, NULL); g_print ("%s completed in %f seconds\n\n", desc, r); g_timer_destroy (t); return (r); } int main (int argc, char* argv[]){ gdouble br[2]; gdouble bo[2]; guint bc = 0; guint i; gchar* limitstr = NULL; gpointer o[][2] = { {"limit", &limitstr}, {NULL}}; gpointer l[][2] = { {"Tree", tree_test}, {"Hash", hash_test}, {"ListSort1", list_sort1_test}, {"ListSort2", list_sort2_test}, {NULL}}; if (argc > 1){ guint a; gulong limit; for (a=0; a