ported havlak and gcbench benchmarks to work with --gc:regions

This commit is contained in:
Andreas Rumpf 2019-01-19 12:48:25 +01:00
commit 2371b4be96
2 changed files with 54 additions and 41 deletions

View file

@ -69,51 +69,54 @@ const
kMinTreeDepth = 4 kMinTreeDepth = 4
kMaxTreeDepth = 16 kMaxTreeDepth = 16
when not declared(withScratchRegion):
template withScratchRegion(body: untyped) = body
# Nodes used by a tree of a given size # Nodes used by a tree of a given size
proc TreeSize(i: int): int = return ((1 shl (i + 1)) - 1) proc treeSize(i: int): int = return ((1 shl (i + 1)) - 1)
# Number of iterations to use for a given tree depth # Number of iterations to use for a given tree depth
proc NumIters(i: int): int = proc numIters(i: int): int =
return 2 * TreeSize(kStretchTreeDepth) div TreeSize(i) return 2 * treeSize(kStretchTreeDepth) div treeSize(i)
# Build tree top down, assigning to older objects. # Build tree top down, assigning to older objects.
proc Populate(iDepth: int, thisNode: PNode) = proc populate(iDepth: int, thisNode: PNode) =
if iDepth <= 0: if iDepth <= 0:
return return
else: else:
new(thisNode.left) new(thisNode.left)
new(thisNode.right) new(thisNode.right)
Populate(iDepth-1, thisNode.left) populate(iDepth-1, thisNode.left)
Populate(iDepth-1, thisNode.right) populate(iDepth-1, thisNode.right)
# Build tree bottom-up # Build tree bottom-up
proc MakeTree(iDepth: int): PNode = proc makeTree(iDepth: int): PNode =
if iDepth <= 0: if iDepth <= 0:
new(result) new(result)
else: else:
return newNode(MakeTree(iDepth-1), MakeTree(iDepth-1)) return newNode(makeTree(iDepth-1), makeTree(iDepth-1))
proc PrintDiagnostics() = proc printDiagnostics() =
echo("Total memory available: " & $getTotalMem() & " bytes") echo("Total memory available: " & $getTotalMem() & " bytes")
echo("Free memory: " & $getFreeMem() & " bytes") echo("Free memory: " & $getFreeMem() & " bytes")
proc TimeConstruction(depth: int) = proc timeConstruction(depth: int) =
var var
root, tempTree: PNode root, tempTree: PNode
iNumIters: int iNumIters: int
iNumIters = NumIters(depth) iNumIters = numIters(depth)
echo("Creating " & $iNumIters & " trees of depth " & $depth) echo("Creating " & $iNumIters & " trees of depth " & $depth)
var t = epochTime() var t = epochTime()
for i in 0..iNumIters-1: for i in 0..iNumIters-1:
new(tempTree) new(tempTree)
Populate(depth, tempTree) populate(depth, tempTree)
tempTree = nil tempTree = nil
echo("\tTop down construction took " & $(epochTime() - t) & "msecs") echo("\tTop down construction took " & $(epochTime() - t) & "msecs")
t = epochTime() t = epochTime()
for i in 0..iNumIters-1: for i in 0..iNumIters-1:
tempTree = MakeTree(depth) tempTree = makeTree(depth)
tempTree = nil tempTree = nil
echo("\tBottom up construction took " & $(epochTime() - t) & "msecs") echo("\tBottom up construction took " & $(epochTime() - t) & "msecs")
@ -127,30 +130,33 @@ proc main() =
echo("Garbage Collector Test") echo("Garbage Collector Test")
echo(" Stretching memory with a binary tree of depth " & $kStretchTreeDepth) echo(" Stretching memory with a binary tree of depth " & $kStretchTreeDepth)
PrintDiagnostics() printDiagnostics()
var t = epochTime() var t = epochTime()
# Stretch the memory space quickly # Stretch the memory space quickly
tempTree = MakeTree(kStretchTreeDepth) withScratchRegion:
tempTree = makeTree(kStretchTreeDepth)
tempTree = nil tempTree = nil
# Create a long lived object # Create a long lived object
echo(" Creating a long-lived binary tree of depth " & echo(" Creating a long-lived binary tree of depth " &
$kLongLivedTreeDepth) $kLongLivedTreeDepth)
new(longLivedTree) new(longLivedTree)
Populate(kLongLivedTreeDepth, longLivedTree) populate(kLongLivedTreeDepth, longLivedTree)
# Create long-lived array, filling half of it # Create long-lived array, filling half of it
echo(" Creating a long-lived array of " & $kArraySize & " doubles") echo(" Creating a long-lived array of " & $kArraySize & " doubles")
withScratchRegion:
newSeq(myarray, kArraySize) newSeq(myarray, kArraySize)
for i in 0..kArraySize div 2 - 1: for i in 0..kArraySize div 2 - 1:
myarray[i] = 1.0 / toFloat(i) myarray[i] = 1.0 / toFloat(i)
PrintDiagnostics() printDiagnostics()
var d = kMinTreeDepth var d = kMinTreeDepth
while d <= kMaxTreeDepth: while d <= kMaxTreeDepth:
TimeConstruction(d) withScratchRegion:
timeConstruction(d)
inc(d, 2) inc(d, 2)
if longLivedTree == nil or myarray[1000] != 1.0/1000.0: if longLivedTree == nil or myarray[1000] != 1.0/1000.0:
@ -159,7 +165,7 @@ proc main() =
# and array to keep them from being optimized away # and array to keep them from being optimized away
var elapsed = epochTime() - t var elapsed = epochTime() - t
PrintDiagnostics() printDiagnostics()
echo("Completed in " & $elapsed & "ms. Success!") echo("Completed in " & $elapsed & "ms. Success!")
when defined(GC_setMaxPause): when defined(GC_setMaxPause):

View file

@ -12,9 +12,10 @@ Found 1 loops (including artificial root node) (5)'''
# bug #3184 # bug #3184
import tables import tables, sequtils, sets, strutils
import sequtils
import sets when not declared(withScratchRegion):
template withScratchRegion(body: untyped) = body
type type
BasicBlock = object BasicBlock = object
@ -418,6 +419,7 @@ proc run(self: var LoopTesterApp) =
echo "15000 dummy loops" echo "15000 dummy loops"
for i in 1..15000: for i in 1..15000:
withScratchRegion:
var h = newHavlakLoopFinder(self.cfg, newLsg()) var h = newHavlakLoopFinder(self.cfg, newLsg())
var res = h.findLoops var res = h.findLoops
@ -446,6 +448,7 @@ proc run(self: var LoopTesterApp) =
var sum = 0 var sum = 0
for i in 1..5: for i in 1..5:
withScratchRegion:
write stdout, "." write stdout, "."
flushFile(stdout) flushFile(stdout)
var hlf = newHavlakLoopFinder(self.cfg, newLsg()) var hlf = newHavlakLoopFinder(self.cfg, newLsg())
@ -453,5 +456,9 @@ proc run(self: var LoopTesterApp) =
#echo getOccupiedMem() #echo getOccupiedMem()
echo "\nFound ", loops, " loops (including artificial root node) (", sum, ")" echo "\nFound ", loops, " loops (including artificial root node) (", sum, ")"
when false:
echo("Total memory available: " & formatSize(getTotalMem()) & " bytes")
echo("Free memory: " & formatSize(getFreeMem()) & " bytes")
var l = newLoopTesterApp() var l = newLoopTesterApp()
l.run l.run