GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
speed3.c
Go to the documentation of this file.
1
/*
2
** Written by David Gerdes US Army Construction Engineering Research Lab
3
** April 1992
4
** Copyright 1992 USA-CERL All rights reserved.
5
**
6
*/
7
8
/*
9
** This is a simple performance comparison between linkm and malloc
10
** I think it better simulates normal use of the library than
11
** speed.c or speed2.c
12
*/
13
#include <stdio.h>
14
#include <grass/linkm.h>
15
16
struct
link
17
{
18
char
let
;
19
struct
link
*
next
;
20
};
21
22
#define LINKM
23
24
int
main
(
int
argc,
char
*argv[])
25
{
26
register
int
i, j;
27
VOID_T
*head;
28
struct
link
List, *tmp, *p;
29
30
31
32
#ifdef LINKM
33
head = (
VOID_T
*)
link_init
(
sizeof
(
struct
link
));
34
#endif
35
36
37
for
(j = 0; j < 1000; j++) {
38
tmp = &List;
39
40
for
(i = 0; i < 2000; i++) {
41
#ifdef LINKM
42
p = (
struct
link
*)
link_new
(head);
43
#else
44
p = (
struct
link
*)malloc(
sizeof
(
struct
link
));
45
#endif
46
tmp->
next
= p;
47
tmp = p;
48
tmp->
next
=
NULL
;
49
}
50
51
for
(p = List.
next
; p !=
NULL
;) {
52
tmp = p->
next
;
53
#ifdef LINKM
54
link_dispose
(head, p);
55
#else
56
free(p);
57
#endif
58
p = tmp;
59
}
60
}
61
62
63
#ifdef LINKM
64
link_cleanup
(head);
65
#endif
66
67
exit(0);
68
}
lib
linkm
speed3.c
Generated on Sun Sep 9 2012 18:55:34 for GRASS Programmer's Manual by
1.8.1.2