summary refs log tree commit diff stats
path: root/tests/gc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gc')
-rw-r--r--tests/gc/closureleak.nim4
-rw-r--r--tests/gc/gcbench.nim330
-rw-r--r--tests/gc/gcleak2.nim2
-rw-r--r--tests/gc/gcleak4.nim4
-rw-r--r--tests/gc/gcleak5.nim4
-rw-r--r--tests/gc/refarrayleak.nim2
6 files changed, 173 insertions, 173 deletions
diff --git a/tests/gc/closureleak.nim b/tests/gc/closureleak.nim
index 1c39f43d5..18d320bdf 100644
--- a/tests/gc/closureleak.nim
+++ b/tests/gc/closureleak.nim
@@ -16,7 +16,7 @@ proc free*(some: ref TFoo) =
   alive_foos.del alive_foos.find(some.id)
 proc newFoo*(): ref TFoo =
   new result, free
-  
+
   result.id = foo_counter
   alive_foos.add result.id
   inc foo_counter
@@ -26,7 +26,7 @@ for i in 0 .. <10:
 
 for i in 0 .. <10:
   let f = newFoo()
-  f.fn = proc = 
+  f.fn = proc =
     echo f.id
 
 GC_fullcollect()
diff --git a/tests/gc/gcbench.nim b/tests/gc/gcbench.nim
index 44d952baa..72337911d 100644
--- a/tests/gc/gcbench.nim
+++ b/tests/gc/gcbench.nim
@@ -1,168 +1,168 @@
-discard """

-  outputsub: "Success!"

-"""

-

-# This is adapted from a benchmark written by John Ellis and Pete Kovac

-# of Post Communications.

-# It was modified by Hans Boehm of Silicon Graphics.

-#

-# This is no substitute for real applications. No actual application

-# is likely to behave in exactly this way. However, this benchmark was

-# designed to be more representative of real applications than other

-# Java GC benchmarks of which we are aware.

-# It attempts to model those properties of allocation requests that

-# are important to current GC techniques.

-# It is designed to be used either to obtain a single overall performance

-# number, or to give a more detailed estimate of how collector

-# performance varies with object lifetimes. It prints the time

-# required to allocate and collect balanced binary trees of various

-# sizes. Smaller trees result in shorter object lifetimes. Each cycle

-# allocates roughly the same amount of memory.

-# Two data structures are kept around during the entire process, so

-# that the measured performance is representative of applications

-# that maintain some live in-memory data. One of these is a tree

-# containing many pointers. The other is a large array containing

-# double precision floating point numbers. Both should be of comparable

-# size.

-#

-# The results are only really meaningful together with a specification

-# of how much memory was used. It is possible to trade memory for

-# better time performance. This benchmark should be run in a 32 MB

-# heap, though we don't currently know how to enforce that uniformly.

-#

-# Unlike the original Ellis and Kovac benchmark, we do not attempt

-# measure pause times. This facility should eventually be added back

-# in. There are several reasons for omitting it for now.  The original

-# implementation depended on assumptions about the thread scheduler

-# that don't hold uniformly. The results really measure both the

-# scheduler and GC. Pause time measurements tend to not fit well with

-# current benchmark suites. As far as we know, none of the current

-# commercial Java implementations seriously attempt to minimize GC pause

-# times.

-#

-# Known deficiencies:

-# - No way to check on memory use

-# - No cyclic data structures

-# - No attempt to measure variation with object size

-# - Results are sensitive to locking cost, but we dont

-#   check for proper locking

-#

-

-import

-  strutils, times

-

-type

-  PNode = ref TNode

-  TNode {.final.} = object

-    left, right: PNode

-    i, j: int

-

-proc newNode(L, r: PNode): PNode =

-  new(result)

-  result.left = L

-  result.right = r

-

-const

-  kStretchTreeDepth = 18 # about 16Mb

-  kLongLivedTreeDepth = 16  # about 4Mb

-  kArraySize  = 500000  # about 4Mb

-  kMinTreeDepth = 4

-  kMaxTreeDepth = 16

-

-# Nodes used by a tree of a given size

-proc TreeSize(i: int): int = return ((1 shl (i + 1)) - 1)

-

-# Number of iterations to use for a given tree depth

-proc NumIters(i: int): int =

-  return 2 * TreeSize(kStretchTreeDepth) div TreeSize(i)

-

-# Build tree top down, assigning to older objects.

-proc Populate(iDepth: int, thisNode: PNode) =

-  if iDepth <= 0:

-    return

-  else:

-    new(thisNode.left)

-    new(thisNode.right)

-    Populate(iDepth-1, thisNode.left)

-    Populate(iDepth-1, thisNode.right)

-

-# Build tree bottom-up

-proc MakeTree(iDepth: int): PNode =

-  if iDepth <= 0:

-    new(result)

-  else:

-    return newNode(MakeTree(iDepth-1), MakeTree(iDepth-1))

-

-proc PrintDiagnostics() =

-  echo("Total memory available: " & $getTotalMem() & " bytes")

-  echo("Free memory: " & $getFreeMem() & " bytes")

-

-proc TimeConstruction(depth: int) =

-  var

-    root, tempTree: PNode

-    iNumIters: int

-

-  iNumIters = NumIters(depth)

-

-  echo("Creating " & $iNumIters & " trees of depth " & $depth)

-  var t = epochTime()

-  for i in 0..iNumIters-1:

-    new(tempTree)

-    Populate(depth, tempTree)

-    tempTree = nil

-  echo("\tTop down construction took " & $(epochTime() - t) & "msecs")

-  t = epochTime()

-  for i in 0..iNumIters-1:

-    tempTree = MakeTree(depth)

-    tempTree = nil

-  echo("\tBottom up construction took " & $(epochTime() - t) & "msecs")

-

-type

-  tMyArray = seq[float]

-

-proc main() =

-  var

-    root, longLivedTree, tempTree: PNode

-    myarray: tMyArray

-

-  echo("Garbage Collector Test")

-  echo(" Stretching memory with a binary tree of depth " & $kStretchTreeDepth)

-  PrintDiagnostics()

-  var t = epochTime()

-

-  # Stretch the memory space quickly

-  tempTree = MakeTree(kStretchTreeDepth)

-  tempTree = nil

-

-  # Create a long lived object

-  echo(" Creating a long-lived binary tree of depth " &

-        $kLongLivedTreeDepth)

-  new(longLivedTree)

-  Populate(kLongLivedTreeDepth, longLivedTree)

-

-  # Create long-lived array, filling half of it

-  echo(" Creating a long-lived array of " & $kArraySize & " doubles")

-  newSeq(myarray, kArraySize)

-  for i in 0..kArraySize div 2 -1:

-    myarray[i] = 1.0 / toFloat(i)

-

-  PrintDiagnostics()

-

-  var d = kMinTreeDepth

-  while d <= kMaxTreeDepth:

-    TimeConstruction(d)

-    inc(d, 2)

-

-  if longLivedTree == nil or myarray[1000] != 1.0/1000.0:

-    echo("Failed")

-    # fake reference to LongLivedTree

-    # and array to keep them from being optimized away

-

-  var elapsed = epochTime() - t

-  PrintDiagnostics()

-  echo("Completed in " & $elapsed & "ms. Success!")

+discard """
+  outputsub: "Success!"
+"""
+
+# This is adapted from a benchmark written by John Ellis and Pete Kovac
+# of Post Communications.
+# It was modified by Hans Boehm of Silicon Graphics.
+#
+# This is no substitute for real applications. No actual application
+# is likely to behave in exactly this way. However, this benchmark was
+# designed to be more representative of real applications than other
+# Java GC benchmarks of which we are aware.
+# It attempts to model those properties of allocation requests that
+# are important to current GC techniques.
+# It is designed to be used either to obtain a single overall performance
+# number, or to give a more detailed estimate of how collector
+# performance varies with object lifetimes. It prints the time
+# required to allocate and collect balanced binary trees of various
+# sizes. Smaller trees result in shorter object lifetimes. Each cycle
+# allocates roughly the same amount of memory.
+# Two data structures are kept around during the entire process, so
+# that the measured performance is representative of applications
+# that maintain some live in-memory data. One of these is a tree
+# containing many pointers. The other is a large array containing
+# double precision floating point numbers. Both should be of comparable
+# size.
+#
+# The results are only really meaningful together with a specification
+# of how much memory was used. It is possible to trade memory for
+# better time performance. This benchmark should be run in a 32 MB
+# heap, though we don't currently know how to enforce that uniformly.
+#
+# Unlike the original Ellis and Kovac benchmark, we do not attempt
+# measure pause times. This facility should eventually be added back
+# in. There are several reasons for omitting it for now.  The original
+# implementation depended on assumptions about the thread scheduler
+# that don't hold uniformly. The results really measure both the
+# scheduler and GC. Pause time measurements tend to not fit well with
+# current benchmark suites. As far as we know, none of the current
+# commercial Java implementations seriously attempt to minimize GC pause
+# times.
+#
+# Known deficiencies:
+# - No way to check on memory use
+# - No cyclic data structures
+# - No attempt to measure variation with object size
+# - Results are sensitive to locking cost, but we dont
+#   check for proper locking
+#
+
+import
+  strutils, times
+
+type
+  PNode = ref TNode
+  TNode {.final.} = object
+    left, right: PNode
+    i, j: int
+
+proc newNode(L, r: PNode): PNode =
+  new(result)
+  result.left = L
+  result.right = r
+
+const
+  kStretchTreeDepth = 18 # about 16Mb
+  kLongLivedTreeDepth = 16  # about 4Mb
+  kArraySize  = 500000  # about 4Mb
+  kMinTreeDepth = 4
+  kMaxTreeDepth = 16
+
+# Nodes used by a tree of a given size
+proc TreeSize(i: int): int = return ((1 shl (i + 1)) - 1)
+
+# Number of iterations to use for a given tree depth
+proc NumIters(i: int): int =
+  return 2 * TreeSize(kStretchTreeDepth) div TreeSize(i)
+
+# Build tree top down, assigning to older objects.
+proc Populate(iDepth: int, thisNode: PNode) =
+  if iDepth <= 0:
+    return
+  else:
+    new(thisNode.left)
+    new(thisNode.right)
+    Populate(iDepth-1, thisNode.left)
+    Populate(iDepth-1, thisNode.right)
+
+# Build tree bottom-up
+proc MakeTree(iDepth: int): PNode =
+  if iDepth <= 0:
+    new(result)
+  else:
+    return newNode(MakeTree(iDepth-1), MakeTree(iDepth-1))
+
+proc PrintDiagnostics() =
+  echo("Total memory available: " & $getTotalMem() & " bytes")
+  echo("Free memory: " & $getFreeMem() & " bytes")
+
+proc TimeConstruction(depth: int) =
+  var
+    root, tempTree: PNode
+    iNumIters: int
+
+  iNumIters = NumIters(depth)
+
+  echo("Creating " & $iNumIters & " trees of depth " & $depth)
+  var t = epochTime()
+  for i in 0..iNumIters-1:
+    new(tempTree)
+    Populate(depth, tempTree)
+    tempTree = nil
+  echo("\tTop down construction took " & $(epochTime() - t) & "msecs")
+  t = epochTime()
+  for i in 0..iNumIters-1:
+    tempTree = MakeTree(depth)
+    tempTree = nil
+  echo("\tBottom up construction took " & $(epochTime() - t) & "msecs")
+
+type
+  tMyArray = seq[float]
+
+proc main() =
+  var
+    root, longLivedTree, tempTree: PNode
+    myarray: tMyArray
+
+  echo("Garbage Collector Test")
+  echo(" Stretching memory with a binary tree of depth " & $kStretchTreeDepth)
+  PrintDiagnostics()
+  var t = epochTime()
+
+  # Stretch the memory space quickly
+  tempTree = MakeTree(kStretchTreeDepth)
+  tempTree = nil
+
+  # Create a long lived object
+  echo(" Creating a long-lived binary tree of depth " &
+        $kLongLivedTreeDepth)
+  new(longLivedTree)
+  Populate(kLongLivedTreeDepth, longLivedTree)
+
+  # Create long-lived array, filling half of it
+  echo(" Creating a long-lived array of " & $kArraySize & " doubles")
+  newSeq(myarray, kArraySize)
+  for i in 0..kArraySize div 2 -1:
+    myarray[i] = 1.0 / toFloat(i)
+
+  PrintDiagnostics()
+
+  var d = kMinTreeDepth
+  while d <= kMaxTreeDepth:
+    TimeConstruction(d)
+    inc(d, 2)
+
+  if longLivedTree == nil or myarray[1000] != 1.0/1000.0:
+    echo("Failed")
+    # fake reference to LongLivedTree
+    # and array to keep them from being optimized away
+
+  var elapsed = epochTime() - t
+  PrintDiagnostics()
+  echo("Completed in " & $elapsed & "ms. Success!")
 
 when defined(GC_setMaxPause):
   GC_setMaxPause 2_000
-

-main()

+
+main()
diff --git a/tests/gc/gcleak2.nim b/tests/gc/gcleak2.nim
index 41d149bed..101421683 100644
--- a/tests/gc/gcleak2.nim
+++ b/tests/gc/gcleak2.nim
@@ -14,7 +14,7 @@ proc MakeObj(): TTestObj =
   result.x = "Hello"
   result.s = @[1,2,3]
 
-proc inProc() = 
+proc inProc() =
   for i in 1 .. 1_000_000:
     when defined(gcMarkAndSweep):
       GC_fullcollect()
diff --git a/tests/gc/gcleak4.nim b/tests/gc/gcleak4.nim
index 54e74ac7b..d93a13854 100644
--- a/tests/gc/gcleak4.nim
+++ b/tests/gc/gcleak4.nim
@@ -14,7 +14,7 @@ type
   TPlusExpr = object of TExpr
     a, b: ref TExpr
     op2: string
-    
+
 method eval(e: ref TExpr): int =
   # override this base method
   quit "to override!"
@@ -30,7 +30,7 @@ proc newLit(x: int): ref TLiteral =
   {.watchpoint: result.}
   result.x = x
   result.op1 = $getOccupiedMem()
-  
+
 proc newPlus(a, b: ref TExpr): ref TPlusExpr =
   new(result)
   {.watchpoint: result.}
diff --git a/tests/gc/gcleak5.nim b/tests/gc/gcleak5.nim
index 9e2948729..6ab50e19e 100644
--- a/tests/gc/gcleak5.nim
+++ b/tests/gc/gcleak5.nim
@@ -11,12 +11,12 @@ proc main =
     var t = getTime()
     var g = t.getGMTime()
     #echo isOnStack(addr g)
-    
+
     if i mod 100 == 0:
       let om = getOccupiedMem()
       #echo "memory: ", om
       if om > 100_000: quit "leak"
-     
+
     inc(i)
     sleep(1)
 
diff --git a/tests/gc/refarrayleak.nim b/tests/gc/refarrayleak.nim
index 12c9145f8..57b489721 100644
--- a/tests/gc/refarrayleak.nim
+++ b/tests/gc/refarrayleak.nim
@@ -28,7 +28,7 @@ proc newArrayHolder: ref TArrayHolder =
 proc loop =
   for i in 0..10000:
     discard newArrayHolder()
-    
+
   if getOccupiedMem() > 300_000:
     echo "still a leak! ", getOccupiedMem()
     quit 1