speed.c 820 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. ** This is a simple best case performance comparison between linkm and malloc
  9. */
  10. #include <stdio.h>
  11. #include <grass/linkm.h>
  12. struct link
  13. {
  14. char let;
  15. struct link *next;
  16. };
  17. /*
  18. #define LINKM
  19. */
  20. int main(int argc, char *argv[])
  21. {
  22. register int i;
  23. VOID_T *head;
  24. struct link List, *tmp, *p;
  25. int rev = 0;
  26. #ifdef LINKM
  27. head = (VOID_T *) link_init(sizeof(struct link));
  28. #endif
  29. for (i = 0; i < 2000000; i++) {
  30. #ifdef LINKM
  31. p = (struct link *)link_new(head);
  32. link_dispose(head, p);
  33. #else
  34. p = (struct link *)malloc(sizeof(struct link));
  35. free(p);
  36. #endif
  37. }
  38. #ifdef LINKM
  39. link_cleanup(head);
  40. #endif
  41. exit(0);
  42. }