GRASS Programmer's Manual  6.4.2(2012)
speed2.c
Go to the documentation of this file.
00001 
00002 
00003 /*
00004  **  Written by David Gerdes  US Army Construction Engineering Research Lab
00005  **     April 1992
00006  **  Copyright 1992 USA-CERL   All rights reserved.
00007  **
00008  */
00009 
00010 /*
00011  **  This is a simple worst case performance comparison between linkm and malloc
00012  */
00013 #include <stdio.h>
00014 #include <grass/linkm.h>
00015 
00016 struct link
00017 {
00018     char let;
00019     struct link *next;
00020 };
00021 
00022 /*
00023    #define LINKM
00024  */
00025 
00026 int main(int argc, char *argv[])
00027 {
00028     register int i;
00029     VOID_T *head;
00030     struct link List, *tmp, *p;
00031     int rev = 0;
00032 
00033 
00034     tmp = &List;
00035 
00036 #ifdef LINKM
00037     /* link_set_chunk_size (2000); */
00038     head = (VOID_T *) link_init(sizeof(struct link));
00039 #endif
00040 
00041 
00042     for (i = 0; i < 2000000; i++) {
00043 #ifdef LINKM
00044         p = (struct link *)link_new(head);
00045 #else
00046         p = (struct link *)malloc(sizeof(struct link));
00047 #endif
00048         tmp->next = p;
00049         tmp = p;
00050         tmp->next = NULL;
00051     }
00052 
00053     for (p = List.next; p != NULL;) {
00054         tmp = p->next;
00055 #ifdef LINKM
00056         link_dispose(head, p);
00057 #else
00058         free(p);
00059 #endif
00060         p = tmp;
00061     }
00062 
00063 
00064 #ifdef LINKM
00065     link_cleanup(head);
00066 #endif
00067 
00068     exit(0);
00069 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines