~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/docs/ref/transapp/writetest.cs

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * writetest --
3
 
 *
4
 
 * $Id$
5
 
 */
6
 
#include <sys/types.h>
7
 
 
8
 
#include <errno.h>
9
 
#include <fcntl.h>
10
 
#include <stdio.h>
11
 
#include <stdlib.h>
12
 
#include <string.h>
13
 
#include <time.h>
14
 
#include <unistd.h>
15
 
 
16
 
void usage __P((void));
17
 
 
18
 
int
19
 
main(argc, argv)
20
 
        int argc;
21
 
        char *argv[];
22
 
{
23
 
        struct timeval start_time, end_time;
24
 
        long usecs;
25
 
        int bytes, ch, cnt, fd, ops;
26
 
        char *fname, buf[100 * 1024];
27
 
 
28
 
        bytes = 256;
29
 
        fname = "testfile";
30
 
        ops = 1000;
31
 
        while ((ch = getopt(argc, argv, "b:f:o:")) != EOF)
32
 
                switch (ch) {
33
 
                case 'b':
34
 
                        if ((bytes = atoi(optarg)) > sizeof(buf)) {
35
 
                                fprintf(stderr,
36
 
                                    "max -b option %d\n", sizeof(buf));
37
 
                                exit (1);
38
 
                        }
39
 
                        break;
40
 
                case 'f':
41
 
                        fname = optarg;
42
 
                        break;
43
 
                case 'o':
44
 
                        if ((ops = atoi(optarg)) <= 0) {
45
 
                                fprintf(stderr, "illegal -o option value\n");
46
 
                                exit (1);
47
 
                        }
48
 
                        break;
49
 
                case '?':
50
 
                default:
51
 
                        usage();
52
 
                }
53
 
        argc -= optind;
54
 
        argv += optind;
55
 
 
56
 
        (void)unlink(fname);
57
 
        if ((fd = open(fname, O_RDWR | O_CREAT, 0666)) == -1) {
58
 
                perror(fname);
59
 
                exit (1);
60
 
        }
61
 
 
62
 
        memset(buf, 0, bytes);
63
 
 
64
 
        printf("running: %d ops\n", ops);
65
 
 
66
 
        (void)gettimeofday(&start_time, NULL);
67
 
        for (cnt = 0; cnt < ops; ++cnt) {
68
 
                if (write(fd, buf, bytes) != bytes) {
69
 
                        fprintf(stderr, "write: %s\n", strerror(errno));
70
 
                        exit (1);
71
 
                }
72
 
                if (lseek(fd, (off_t)0, SEEK_SET) == -1) {
73
 
                        fprintf(stderr, "lseek: %s\n", strerror(errno));
74
 
                        exit (1);
75
 
                }
76
 
                if (fsync(fd) != 0) {
77
 
                        fprintf(stderr, "fsync: %s\n", strerror(errno));
78
 
                        exit (1);
79
 
                }
80
 
        }
81
 
        (void)gettimeofday(&end_time, NULL);
82
 
 
83
 
        if (end_time.tv_sec != start_time.tv_sec) {
84
 
                end_time.tv_usec += 1000000;
85
 
                --end_time.tv_sec;
86
 
        }
87
 
        usecs = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
88
 
            end_time.tv_usec - start_time.tv_usec;
89
 
        printf("Elapsed time: %ld.%06ld seconds\n",
90
 
            usecs / 1000000, usecs % 1000000);
91
 
        printf("%d ops: %7.2f ops per second\n",
92
 
            ops, (float)1000000 * ops/usecs);
93
 
 
94
 
        (void)unlink(fname);
95
 
        exit (0);
96
 
}
97
 
 
98
 
void
99
 
usage()
100
 
{
101
 
        (void)fprintf(stderr,
102
 
            "usage: testfile [-b bytes] [-f file] [-o ops]\n");
103
 
        exit(1);
104
 
}