Add a new 'btree' benchmark, that does a lot of object creation and recursive function calls.
[BENCHMARKS] * NEW: Add a new 'btree' benchmark, that does a lot of object creation and recursive function calls. * NEW: Rename the 'string' benchmark as 'string1', to avoid name clashes in Python. * BUG: Fix the HTML table generation.
This commit is contained in:
parent
c6ef469966
commit
de200aac4c
10 changed files with 257 additions and 40 deletions
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/env gbs3
|
||||
|
||||
Private $fCompileTime as Float
|
||||
Private $fCompileTime As Float
|
||||
|
||||
Private Sub RunScript(sScript As String, sRun As String, bGambasOnly As Boolean) As Float
|
||||
|
||||
Dim aResult as String[]
|
||||
Dim aResult As String[]
|
||||
Dim sResult As String
|
||||
Dim fTime As Float
|
||||
|
||||
|
@ -39,10 +39,10 @@ Private Sub FormatResult(cResult As Collection, iCount As Integer, sLang As Stri
|
|||
Dim sFormat As String
|
||||
Dim sTest As String
|
||||
|
||||
If cResult[sLang] <= 0 Then Return "-"
|
||||
If cResult[sLang] <= 0 Then Return Format("30", "0.00") & "+"
|
||||
|
||||
For Each sTest In ["python", "perl", "java","gambas"]
|
||||
If cResult[sTest] < cResult[sLang] Then
|
||||
For Each sTest In ["python", "perl", "java", "gambas"]
|
||||
If cResult[sTest] > 0 And If cResult[sTest] < cResult[sLang] Then
|
||||
bBetter = False
|
||||
Break
|
||||
Endif
|
||||
|
@ -66,15 +66,17 @@ Dim iCount As Integer = 1
|
|||
Dim I As Integer
|
||||
Dim fTime As Float
|
||||
|
||||
Shell "rm -rf " & Shell$(Application.Dir &/ " __pycache__") Wait
|
||||
|
||||
For I = 1 To Args.Max
|
||||
|
||||
If Args[I] = "-gambas" Then
|
||||
bGambasOnly = True
|
||||
Else If Args[I] = "-count" Then
|
||||
If I < Args.Max And If Args[I + 1] Not Begins "-" Then
|
||||
Try iCount = Max(1, CInt(Args[I + 1]))
|
||||
inc I
|
||||
Endif
|
||||
Else If Args[I] = "-count" Then
|
||||
If I < Args.Max And If Args[I + 1] Not Begins "-" Then
|
||||
Try iCount = Max(1, CInt(Args[I + 1]))
|
||||
Inc I
|
||||
Endif
|
||||
Else
|
||||
sBenchmarkOnly = Args[I]
|
||||
Endif
|
||||
|
@ -83,37 +85,40 @@ Next
|
|||
|
||||
For I = 1 To iCount
|
||||
|
||||
If iCount > 1 Then Print "-------- Run #"; I;" --------"
|
||||
If iCount > 1 Then Print "-------- Run #"; I; " --------"
|
||||
|
||||
For Each sBenchmark In Dir(Application.Dir, "*.gbs").Sort()
|
||||
For Each sBenchmark In Dir(Application.Dir, "*.gbs").Sort()
|
||||
|
||||
sBenchmark = File.BaseName(sBenchmark)
|
||||
If sBenchmark = "benchmark" Then Continue
|
||||
If sBenchmarkOnly And If sBenchmark <> sBenchmarkOnly Then Continue
|
||||
sBenchmark = File.BaseName(sBenchmark)
|
||||
If sBenchmark = "benchmark" Then Continue
|
||||
If sBenchmarkOnly And If sBenchmark <> sBenchmarkOnly Then Continue
|
||||
|
||||
cResult = cAllResult[sBenchmark]
|
||||
If Not cResult Then
|
||||
cResult = New Collection
|
||||
cResult.Default = 0.0
|
||||
cResult!name = sBenchmark
|
||||
cAllResult[sBenchmark] = cResult
|
||||
Endif
|
||||
|
||||
If Not bGambasOnly Then
|
||||
cResult!python += RunScript(sBenchmark & ".py", "python", bGambasOnly)
|
||||
cResult!perl += RunScript(sBenchmark & ".pl", "perl", bGambasOnly)
|
||||
If sBenchmark Not Begins "string" Then
|
||||
cResult!java += RunScript(sBenchmark & ".jvs", "java -Xint --source 11", bGambasOnly)
|
||||
Endif
|
||||
cResult!javajit += RunScript(sBenchmark & ".jvs", "java --source 11", bGambasOnly)
|
||||
Endif
|
||||
fTime = RunScript(sBenchmark & ".gbs", "gbs3 -f -U -c", bGambasOnly)
|
||||
cResult!gambasjit += fTime
|
||||
cResult!gambasjitwct += fTime - $fCompileTime
|
||||
cResult!gambas += RunScript(sBenchmark & ".gbs", "gbs3 -c", bGambasOnly)
|
||||
cResult = cAllResult[sBenchmark]
|
||||
If Not cResult Then
|
||||
cResult = New Collection
|
||||
cResult.Default = 0.0
|
||||
cResult!name = sBenchmark
|
||||
cAllResult[sBenchmark] = cResult
|
||||
Endif
|
||||
|
||||
If Not bGambasOnly Then
|
||||
If sBenchmark <> "string2" Then
|
||||
cResult!python += RunScript(sBenchmark & ".py", "python", bGambasOnly)
|
||||
Endif
|
||||
cResult!perl += RunScript(sBenchmark & ".pl", "perl", bGambasOnly)
|
||||
If sBenchmark Not Begins "string" Then
|
||||
cResult!java += RunScript(sBenchmark & ".jvs", "java -Xint --source 11", bGambasOnly)
|
||||
Endif
|
||||
cResult!javajit += RunScript(sBenchmark & ".jvs", "java --source 11", bGambasOnly)
|
||||
Endif
|
||||
|
||||
Next
|
||||
|
||||
fTime = RunScript(sBenchmark & ".gbs", "gbs3 -f -U -c", bGambasOnly)
|
||||
cResult!gambasjit += fTime
|
||||
cResult!gambasjitwct += fTime - $fCompileTime
|
||||
cResult!gambas += RunScript(sBenchmark & ".gbs", "gbs3 -c", bGambasOnly)
|
||||
|
||||
Next
|
||||
|
||||
Next
|
||||
|
||||
Print
|
||||
|
@ -139,7 +144,7 @@ Print
|
|||
If bGambasOnly Then
|
||||
|
||||
For Each cResult In cAllResult
|
||||
Print cResult!name; Space$(20 - Len(cResult!name)); ": "; Format(cResult!gambas / iCount, "0.00"); " / ";Format(cResult!gambasjit / iCount, "0.00");" (jit)"; " / ";Format(cResult!gambasjitwct / iCount, "0.00");" (jit without compilation time)"
|
||||
Print cResult!name; Space$(20 - Len(cResult!name)); ": "; Format(cResult!gambas / iCount, "0.00"); " / "; Format(cResult!gambasjit / iCount, "0.00"); " (jit)"; " / "; Format(cResult!gambasjitwct / iCount, "0.00"); " (jit without compilation time)"
|
||||
Next
|
||||
|
||||
Else
|
||||
|
|
69
benchmark/btree.gbs
Executable file
69
benchmark/btree.gbs
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env gbs3
|
||||
|
||||
Class TreeNode
|
||||
|
||||
Public Left As TreeNode
|
||||
Public Right As TreeNode
|
||||
|
||||
Static Public Sub Create(D As Integer) As TreeNode
|
||||
|
||||
Return ChildTreeNodes(D)
|
||||
|
||||
End
|
||||
|
||||
Static Public Sub ChildTreeNodes(D As Integer) As TreeNode
|
||||
|
||||
Dim hNode As TreeNode = new TreeNode
|
||||
|
||||
If D > 0 Then
|
||||
|
||||
hNode.Left = ChildTreeNodes(D - 1)
|
||||
hNode.Right = ChildTreeNodes(D - 1)
|
||||
|
||||
Endif
|
||||
|
||||
Return hNode
|
||||
|
||||
End
|
||||
|
||||
Public Sub Check() As Integer
|
||||
|
||||
If Not Left Then Return 1
|
||||
Return Left.Check() + Right.Check() + 1
|
||||
|
||||
End
|
||||
|
||||
End Class
|
||||
|
||||
Dim iMinDepth As Integer = 4
|
||||
Dim iMaxDepth As Integer = 16
|
||||
Dim iStretchDepth As Integer = iMaxDepth + 1
|
||||
Dim iCheck As Integer
|
||||
Dim hTree As TreeNode
|
||||
Dim D, I As Integer
|
||||
Dim iIterations As Integer
|
||||
|
||||
iCheck = TreeNode.Create(iStretchDepth).Check()
|
||||
|
||||
Print "stretch tree of depth "; iMaxDepth + 1; "\t check: "; iCheck
|
||||
|
||||
hTree = TreeNode.Create(iMaxDepth)
|
||||
|
||||
For D = iMinDepth To iMaxDepth Step 2
|
||||
|
||||
iCheck = 0
|
||||
iIterations = Shl(1, iMaxDepth - D + iMinDepth)
|
||||
|
||||
For I = 1 To iIterations
|
||||
|
||||
iCheck += TreeNode.Create(D).Check()
|
||||
|
||||
Next
|
||||
|
||||
Print iIterations;"\t trees of depth "; D; "\t check: ";iCheck
|
||||
|
||||
Next
|
||||
|
||||
Print "long lived tree of depth "; iMaxDepth; "\t check: "; hTree.Check()
|
||||
|
||||
Error CStr(Jit.Time)
|
52
benchmark/btree.jvs
Executable file
52
benchmark/btree.jvs
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/java --source 11
|
||||
|
||||
public class binarytrees {
|
||||
public static void main(String[] args) throws Exception {
|
||||
int n = args.length > 0 ? Integer.parseInt(args[0]) : 0;
|
||||
int minDepth = 4;
|
||||
int maxDepth = 16;
|
||||
int stretchDepth = maxDepth + 1;
|
||||
int check = (TreeNode.create(stretchDepth)).check();
|
||||
|
||||
System.out.println("stretch tree of depth " + (maxDepth + 1) + "\t check: " + check);
|
||||
|
||||
TreeNode longLivedTree = TreeNode.create(maxDepth);
|
||||
for (int depth = minDepth; depth <= maxDepth; depth += 2)
|
||||
{
|
||||
int iterations = 1 << (maxDepth - depth + minDepth);
|
||||
check = 0;
|
||||
|
||||
for (int i = 1; i <= iterations; i++)
|
||||
{
|
||||
check += (TreeNode.create(depth)).check();
|
||||
}
|
||||
System.out.println(iterations + "\t trees of depth " + depth + "\t check: " + check);
|
||||
}
|
||||
|
||||
System.out.println("long lived tree of depth " + maxDepth + "\t check: " + longLivedTree.check());
|
||||
}
|
||||
|
||||
static class TreeNode {
|
||||
TreeNode left, right;
|
||||
|
||||
static TreeNode create(int depth)
|
||||
{
|
||||
return ChildTreeNodes(depth);
|
||||
}
|
||||
|
||||
static TreeNode ChildTreeNodes(int depth)
|
||||
{
|
||||
TreeNode node = new TreeNode();
|
||||
if (depth > 0)
|
||||
{
|
||||
node.left = ChildTreeNodes(depth - 1);
|
||||
node.right = ChildTreeNodes(depth - 1);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
int check() {
|
||||
return left == null ? 1 : left.check() + right.check() + 1;
|
||||
}
|
||||
}
|
||||
}
|
47
benchmark/btree.pl
Executable file
47
benchmark/btree.pl
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
run( @ARGV );
|
||||
|
||||
sub bottomup_tree {
|
||||
my $depth = shift;
|
||||
return 0 unless $depth;
|
||||
--$depth;
|
||||
[ bottomup_tree($depth), bottomup_tree($depth) ];
|
||||
}
|
||||
|
||||
sub check_tree {
|
||||
return 1 unless ref $_[0];
|
||||
1 + check_tree($_[0][0]) + check_tree($_[0][1]);
|
||||
}
|
||||
|
||||
sub stretch_tree {
|
||||
my $stretch_depth = shift;
|
||||
my $stretch_tree = bottomup_tree($stretch_depth);
|
||||
print "stretch tree of depth $stretch_depth\t check: ",
|
||||
check_tree($stretch_tree), "\n";
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $max_depth = 16;
|
||||
my $min_depth = 4;
|
||||
|
||||
$max_depth = $min_depth + 2 if $min_depth + 2 > $max_depth;
|
||||
|
||||
stretch_tree( $max_depth + 1 );
|
||||
|
||||
my $longlived_tree = bottomup_tree($max_depth);
|
||||
|
||||
for ( my $depth = $min_depth; $depth <= $max_depth; $depth += 2 ) {
|
||||
my $iterations = 2**($max_depth - $depth + $min_depth);
|
||||
my $check = 0;
|
||||
|
||||
foreach (1..$iterations) {
|
||||
$check += check_tree( bottomup_tree($depth) );
|
||||
}
|
||||
|
||||
print $iterations, "\t trees of depth $depth\t check: ", $check, "\n"
|
||||
}
|
||||
|
||||
print "long lived tree of depth $max_depth\t check: ",
|
||||
check_tree($longlived_tree), "\n"
|
||||
}
|
44
benchmark/btree.py
Executable file
44
benchmark/btree.py
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
|
||||
class TreeNode:
|
||||
left = None
|
||||
right = None
|
||||
|
||||
def check(self):
|
||||
if self.left == None:
|
||||
return 1
|
||||
return self.left.check() + self.right.check() + 1
|
||||
|
||||
def CreateTreeNode(depth):
|
||||
return ChildTreeNodes(depth)
|
||||
|
||||
def ChildTreeNodes(depth):
|
||||
node = TreeNode()
|
||||
if depth > 0:
|
||||
node.left = ChildTreeNodes(depth - 1)
|
||||
node.right = ChildTreeNodes(depth - 1)
|
||||
return node
|
||||
|
||||
|
||||
min_depth = 4
|
||||
max_depth = 16
|
||||
stretch_depth = max_depth + 1
|
||||
|
||||
print("stretch tree of depth %d\t check:" %
|
||||
stretch_depth, CreateTreeNode(stretch_depth).check())
|
||||
|
||||
long_lived_tree = CreateTreeNode(max_depth)
|
||||
|
||||
for depth in range(min_depth, stretch_depth, 2):
|
||||
|
||||
check = 0
|
||||
iterations = 2**(max_depth - depth + min_depth)
|
||||
for i in range(1, iterations + 1):
|
||||
check += CreateTreeNode(depth).check()
|
||||
|
||||
print("%d\t trees of depth %d\t check:" % (iterations, depth), check)
|
||||
|
||||
print("long lived tree of depth %d\t check:" %
|
||||
max_depth, long_lived_tree.check())
|
|
@ -73,6 +73,7 @@ public final class mandelbrot
|
|||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
import time
|
||||
import sys
|
||||
|
||||
|
@ -16,7 +15,7 @@ i = 0
|
|||
while (i < imax+1000):
|
||||
i = i + 1
|
||||
gstr += str
|
||||
gstr = re.sub('efgh','____',gstr)
|
||||
gstr = gstr.replace('efgh','____')
|
||||
lngth = len(gstr)
|
||||
if (lngth % (1024*64) == 0):
|
||||
print(int(time.time()-starttime),"sec\t\t",(lngth/1024),"kb")
|
Loading…
Reference in a new issue