GRASS Programmer's Manual  6.4.2(2012)
speed.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 best case performance comparison between linkm and malloc
00010  */
00011 #include <stdio.h>
00012 #include <grass/linkm.h>
00013 
00014 struct link
00015 {
00016     char let;
00017     struct link *next;
00018 };
00019 
00020 /*
00021    #define LINKM
00022  */
00023 
00024 int main(int argc, char *argv[])
00025 {
00026     register int i;
00027     VOID_T *head;
00028     struct link List, *tmp, *p;
00029     int rev = 0;
00030 
00031 
00032 
00033 #ifdef LINKM
00034     head = (VOID_T *) link_init(sizeof(struct link));
00035 #endif
00036 
00037 
00038     for (i = 0; i < 2000000; i++) {
00039 #ifdef LINKM
00040         p = (struct link *)link_new(head);
00041         link_dispose(head, p);
00042 #else
00043         p = (struct link *)malloc(sizeof(struct link));
00044         free(p);
00045 #endif
00046     }
00047 
00048 #ifdef LINKM
00049     link_cleanup(head);
00050 #endif
00051 
00052     exit(0);
00053 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines