torcbench.nim 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. discard """
  2. output: '''true peak memory: true'''
  3. cmd: "nim c --gc:orc -d:release $file"
  4. """
  5. import lists, strutils, times
  6. type
  7. Base = ref object of RootObj
  8. Node = ref object of Base
  9. parent: DoublyLinkedList[string]
  10. le, ri: Node
  11. self: Node # in order to create a cycle
  12. proc buildTree(parent: DoublyLinkedList[string]; depth: int): Node =
  13. if depth == 0:
  14. result = nil
  15. elif depth == 1:
  16. result = Node(parent: parent, le: nil, ri: nil, self: nil)
  17. when not defined(gcArc):
  18. result.self = result
  19. else:
  20. result = Node(parent: parent, le: buildTree(parent, depth - 1), ri: buildTree(parent, depth - 2), self: nil)
  21. result.self = result
  22. proc main() =
  23. for i in countup(1, 100):
  24. var leakList = initDoublyLinkedList[string]()
  25. for j in countup(1, 5000):
  26. leakList.append(newString(200))
  27. #GC_fullCollect()
  28. for i in 0..400:
  29. discard buildTree(leakList, 8)
  30. main()
  31. GC_fullCollect()
  32. echo getOccupiedMem() < 10 * 1024 * 1024, " peak memory: ", getMaxMem() < 10 * 1024 * 1024