~ubuntu-branches/ubuntu/precise/hardinfo/precise

« back to all changes in this revision

Viewing changes to arch/common/zlib.h

  • Committer: Bazaar Package Importer
  • Author(s): Agney Lopes Roth Ferraz
  • Date: 2009-03-28 22:55:02 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090328225502-p4bnvi8q6hr95cij
Tags: 0.5c-1
New upstream version. 
(Closes: #517591, #511237, #457703, #519256, #449250, #457820, #497758) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *    HardInfo - Displays System Information
3
 
 *    Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>
4
 
 *
5
 
 *    This program is free software; you can redistribute it and/or modify
6
 
 *    it under the terms of the GNU General Public License as published by
7
 
 *    the Free Software Foundation, version 2.
8
 
 *
9
 
 *    This program is distributed in the hope that it will be useful,
10
 
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 *    GNU General Public License for more details.
13
 
 *
14
 
 *    You should have received a copy of the GNU General Public License
15
 
 *    along with this program; if not, write to the Free Software
16
 
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17
 
 */
18
 
 
19
 
static void
20
 
benchmark_zlib(void)
21
 
{
22
 
    GModule *libz;
23
 
    static gulong (*compressBound) (glong srclen) = NULL;
24
 
    static gint (*compress) (gchar *dst, glong *dstlen,
25
 
                             const gchar *src, glong srclen) = NULL;
26
 
 
27
 
    if (!(compress && compressBound)) {
28
 
        libz = g_module_open("libz", G_MODULE_BIND_LAZY);
29
 
        if (!libz) {
30
 
            libz = g_module_open("/usr/lib/libz.so.1", G_MODULE_BIND_LAZY);
31
 
            if (!libz) {
32
 
                g_warning("Cannot load ZLib: %s", g_module_error());
33
 
                return;
34
 
            }
35
 
        }
36
 
 
37
 
        if (!g_module_symbol(libz, "compress", (gpointer) & compress)
38
 
            || !g_module_symbol(libz, "compressBound", (gpointer) & compressBound)) {
39
 
            
40
 
            g_module_close(libz);
41
 
            return;
42
 
        }
43
 
    }
44
 
 
45
 
    shell_view_set_enabled(FALSE);
46
 
 
47
 
    int i;
48
 
    GTimer *timer = g_timer_new();
49
 
    gdouble elapsed = 0;
50
 
    gchar src[65536], *tmpsrc;
51
 
    glong srclen = 65536;
52
 
    gchar *bdata_path;
53
 
    
54
 
    bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
55
 
    if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) {
56
 
        g_free(bdata_path);
57
 
        return;
58
 
    }     
59
 
    
60
 
    shell_status_update("Compressing 64MB with default options...");
61
 
    
62
 
    for (i = 0; i <= 1000; i++) { 
63
 
        g_timer_start(timer);
64
 
        
65
 
        gchar *dst;
66
 
        glong dstlen = compressBound(srclen);
67
 
        
68
 
        dst = g_new0(gchar, dstlen);
69
 
        compress(dst, &dstlen, src, srclen);
70
 
 
71
 
        g_timer_stop(timer);
72
 
        elapsed += g_timer_elapsed(timer, NULL);
73
 
        g_free(dst);
74
 
        
75
 
        shell_status_set_percentage(i/10);
76
 
    }
77
 
    
78
 
    g_timer_destroy(timer);
79
 
    g_free(bdata_path);
80
 
    
81
 
    bench_results[BENCHMARK_ZLIB] = 65536.0 / elapsed;
82
 
}