ported havlak and gcbench benchmarks to work with --gc:regions
This commit is contained in:
parent
9985706fb8
commit
2371b4be96
2 changed files with 54 additions and 41 deletions
|
|
@ -65,55 +65,58 @@ proc newNode(L, r: PNode): PNode =
|
||||||
const
|
const
|
||||||
kStretchTreeDepth = 18 # about 16Mb
|
kStretchTreeDepth = 18 # about 16Mb
|
||||||
kLongLivedTreeDepth = 16 # about 4Mb
|
kLongLivedTreeDepth = 16 # about 4Mb
|
||||||
kArraySize = 500000 # about 4Mb
|
kArraySize = 500000 # about 4Mb
|
||||||
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,39 +130,42 @@ 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 = nil
|
tempTree = makeTree(kStretchTreeDepth)
|
||||||
|
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")
|
||||||
newSeq(myarray, kArraySize)
|
withScratchRegion:
|
||||||
for i in 0..kArraySize div 2 - 1:
|
newSeq(myarray, kArraySize)
|
||||||
myarray[i] = 1.0 / toFloat(i)
|
for i in 0..kArraySize div 2 - 1:
|
||||||
|
myarray[i] = 1.0 / toFloat(i)
|
||||||
|
|
||||||
PrintDiagnostics()
|
printDiagnostics()
|
||||||
|
|
||||||
var d = kMinTreeDepth
|
var d = kMinTreeDepth
|
||||||
while d <= kMaxTreeDepth:
|
while d <= kMaxTreeDepth:
|
||||||
TimeConstruction(d)
|
withScratchRegion:
|
||||||
inc(d, 2)
|
timeConstruction(d)
|
||||||
|
inc(d, 2)
|
||||||
|
|
||||||
if longLivedTree == nil or myarray[1000] != 1.0/1000.0:
|
if longLivedTree == nil or myarray[1000] != 1.0/1000.0:
|
||||||
echo("Failed")
|
echo("Failed")
|
||||||
# fake reference to LongLivedTree
|
# fake reference to LongLivedTree
|
||||||
# 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):
|
||||||
|
|
|
||||||
|
|
@ -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,8 +419,9 @@ proc run(self: var LoopTesterApp) =
|
||||||
echo "15000 dummy loops"
|
echo "15000 dummy loops"
|
||||||
|
|
||||||
for i in 1..15000:
|
for i in 1..15000:
|
||||||
var h = newHavlakLoopFinder(self.cfg, newLsg())
|
withScratchRegion:
|
||||||
var res = h.findLoops
|
var h = newHavlakLoopFinder(self.cfg, newLsg())
|
||||||
|
var res = h.findLoops
|
||||||
|
|
||||||
echo "Constructing CFG..."
|
echo "Constructing CFG..."
|
||||||
var n = 2
|
var n = 2
|
||||||
|
|
@ -446,12 +448,17 @@ proc run(self: var LoopTesterApp) =
|
||||||
|
|
||||||
var sum = 0
|
var sum = 0
|
||||||
for i in 1..5:
|
for i in 1..5:
|
||||||
write stdout, "."
|
withScratchRegion:
|
||||||
flushFile(stdout)
|
write stdout, "."
|
||||||
var hlf = newHavlakLoopFinder(self.cfg, newLsg())
|
flushFile(stdout)
|
||||||
sum += hlf.findLoops
|
var hlf = newHavlakLoopFinder(self.cfg, newLsg())
|
||||||
#echo getOccupiedMem()
|
sum += hlf.findLoops
|
||||||
|
#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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue