GRASS Programmer's Manual  6.4.2(2012)
speed3.c
Go to the documentation of this file.
00001 /*
00002  **  Written by David Gerdes  US Army Construction Engineering Research Lab
00003  **     April 1992
00004  **  Copyright 1992 USA-CERL   All rights reserved.
00005  **
00006  */
00007 
00008 /*
00009  **  This is a simple performance comparison between linkm and malloc
00010  **   I think it better simulates normal use of the library than
00011  **   speed.c or speed2.c
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 #define LINKM
00023 
00024 int main(int argc, char *argv[])
00025 {
00026     register int i, j;
00027     VOID_T *head;
00028     struct link List, *tmp, *p;
00029 
00030 
00031 
00032 #ifdef LINKM
00033     head = (VOID_T *) link_init(sizeof(struct link));
00034 #endif
00035 
00036 
00037     for (j = 0; j < 1000; j++) {
00038         tmp = &List;
00039 
00040         for (i = 0; i < 2000; i++) {
00041 #ifdef LINKM
00042             p = (struct link *)link_new(head);
00043 #else
00044             p = (struct link *)malloc(sizeof(struct link));
00045 #endif
00046             tmp->next = p;
00047             tmp = p;
00048             tmp->next = NULL;
00049         }
00050 
00051         for (p = List.next; p != NULL;) {
00052             tmp = p->next;
00053 #ifdef LINKM
00054             link_dispose(head, p);
00055 #else
00056             free(p);
00057 #endif
00058             p = tmp;
00059         }
00060     }
00061 
00062 
00063 #ifdef LINKM
00064     link_cleanup(head);
00065 #endif
00066 
00067     exit(0);
00068 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines