speed2.c 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 worst 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. tmp = &List;
  27. #ifdef LINKM
  28. /* link_set_chunk_size (2000); */
  29. head = (VOID_T *) link_init(sizeof(struct link));
  30. #endif
  31. for (i = 0; i < 2000000; i++) {
  32. #ifdef LINKM
  33. p = (struct link *)link_new(head);
  34. #else
  35. p = (struct link *)malloc(sizeof(struct link));
  36. #endif
  37. tmp->next = p;
  38. tmp = p;
  39. tmp->next = NULL;
  40. }
  41. for (p = List.next; p != NULL;) {
  42. tmp = p->next;
  43. #ifdef LINKM
  44. link_dispose(head, p);
  45. #else
  46. free(p);
  47. #endif
  48. p = tmp;
  49. }
  50. #ifdef LINKM
  51. link_cleanup(head);
  52. #endif
  53. exit(0);
  54. }