2014-10-31 17:36:02 +01:00
|
|
|
#!/usr/bin/env gbs3
|
|
|
|
|
2018-07-03 00:54:34 +02:00
|
|
|
Private $fCompileTime as Float
|
|
|
|
|
2014-11-09 23:06:07 +01:00
|
|
|
Private Sub RunScript(sScript As String, sRun As String, bGambasOnly As Boolean) As Float
|
2014-10-31 17:36:02 +01:00
|
|
|
|
2018-07-03 00:54:34 +02:00
|
|
|
Dim aResult as String[]
|
2014-10-31 17:36:02 +01:00
|
|
|
Dim sResult As String
|
|
|
|
Dim fTime As Float
|
|
|
|
|
2014-11-09 23:06:07 +01:00
|
|
|
If bGambasOnly Then
|
|
|
|
Print "Running benchmark: '"; sRun; " "; sScript; "'"
|
|
|
|
Else
|
|
|
|
Print "<!-- Running benchmark: '"; sRun; " "; sScript; "' -->"
|
|
|
|
Endif
|
2014-10-31 17:36:02 +01:00
|
|
|
|
|
|
|
Shell "/usr/bin/time -v " & sRun & " " & sScript & " 2>&1 >/dev/null" To sResult
|
|
|
|
If Not sResult Then Error.Raise("Script '" & sRun & " " & sScript & "' failed!")
|
2018-07-03 00:54:34 +02:00
|
|
|
aResult = Split(sResult, "\n")
|
|
|
|
For Each sResult In aResult
|
2014-10-31 17:36:02 +01:00
|
|
|
sResult = Trim(sResult)
|
|
|
|
If sResult Begins "User time" Or If sResult Begins "System time" Then
|
2014-11-03 20:33:05 +01:00
|
|
|
fTime += CFloat(Mid$(sResult, InStr(sResult, ":") + 2))
|
2014-10-31 17:36:02 +01:00
|
|
|
Endif
|
|
|
|
Next
|
|
|
|
|
2018-07-03 00:54:34 +02:00
|
|
|
$fCompileTime = 0
|
|
|
|
Try $fCompileTime = CFloat(Trim(aResult[0]))
|
|
|
|
|
2014-10-31 17:36:02 +01:00
|
|
|
Return fTime
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2014-11-03 00:10:47 +01:00
|
|
|
Private Sub FormatResult(cResult As Collection, sLang As String) As String
|
|
|
|
|
|
|
|
Dim bBetter As Boolean = True
|
|
|
|
Dim sFormat As String
|
|
|
|
Dim sTest As String
|
|
|
|
|
2014-11-03 20:33:05 +01:00
|
|
|
For Each sTest In ["python", "perl", "gambas"]
|
2014-11-03 00:10:47 +01:00
|
|
|
If cResult[sTest] < cResult[sLang] Then
|
|
|
|
bBetter = False
|
|
|
|
Break
|
|
|
|
Endif
|
|
|
|
Next
|
|
|
|
|
|
|
|
sFormat = Format(cResult[sLang], "0.00")
|
|
|
|
If bBetter Then sFormat = "<b>" & sFormat & "</b>"
|
|
|
|
Return sFormat
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2014-10-31 17:36:02 +01:00
|
|
|
Dim sBenchmark As String
|
|
|
|
Dim cResult As Collection
|
|
|
|
Dim aResult As New Collection[]
|
|
|
|
Dim sLang As String
|
2014-11-03 00:10:47 +01:00
|
|
|
Dim sResult As String
|
|
|
|
Dim iPos As Integer
|
2014-11-09 23:06:07 +01:00
|
|
|
Dim bGambasOnly As Boolean
|
|
|
|
Dim sBenchmarkOnly As String
|
|
|
|
Dim I As Integer
|
|
|
|
|
|
|
|
For I = 1 To Args.Max
|
|
|
|
|
|
|
|
If Args[I] = "-gambas" Then
|
|
|
|
bGambasOnly = True
|
|
|
|
Else
|
|
|
|
sBenchmarkOnly = Args[I]
|
|
|
|
Endif
|
|
|
|
|
|
|
|
Next
|
2014-10-31 17:36:02 +01:00
|
|
|
|
|
|
|
For Each sBenchmark In Dir(Application.Dir, "*.gbs")
|
|
|
|
|
|
|
|
sBenchmark = File.BaseName(sBenchmark)
|
|
|
|
If sBenchmark = "benchmark" Then Continue
|
2014-11-09 23:06:07 +01:00
|
|
|
If sBenchmarkOnly And If sBenchmark <> sBenchmarkOnly Then Continue
|
2014-10-31 17:36:02 +01:00
|
|
|
|
|
|
|
cResult = New Collection
|
|
|
|
aResult.Add(cResult)
|
|
|
|
|
|
|
|
cResult!name = sBenchmark
|
2018-11-27 03:02:23 +01:00
|
|
|
cResult!gambasjit = RunScript(sBenchmark & ".gbs", "gbs3 -f -U -c", bGambasOnly)
|
2018-07-03 00:54:34 +02:00
|
|
|
cResult!gambasjitwct = cResult!gambasjit - $fCompileTime
|
2014-11-09 23:06:07 +01:00
|
|
|
cResult!gambas = RunScript(sBenchmark & ".gbs", "gbs3 -c", bGambasOnly)
|
|
|
|
If Not bGambasOnly Then cResult!python = RunScript(sBenchmark & ".py", "python", bGambasOnly)
|
|
|
|
If Not bGambasOnly Then cResult!perl = RunScript(sBenchmark & ".pl", "perl", bGambasOnly)
|
2014-10-31 17:36:02 +01:00
|
|
|
|
|
|
|
Next
|
|
|
|
|
2014-11-03 00:10:47 +01:00
|
|
|
' Print "<div style=\"border:solid 1px gray;padding:8px;display:inline-table;background:\">"
|
|
|
|
'
|
|
|
|
' Exec ["uname", "-srv"] To sResult
|
|
|
|
' Print "<b>Kernel:</b> ";Html(sResult);"<br>"
|
|
|
|
'
|
|
|
|
' Exec ["cat", "/proc/cpuinfo"] To sResult
|
|
|
|
' For Each sResult In Split(sResult, "\n")
|
|
|
|
' If sResult Begins "model name" Then
|
|
|
|
' iPos = Instr(sResult, ":")
|
|
|
|
' If iPos Then
|
|
|
|
' Print "<b>CPU:</b> ";Html(Mid$(sResult, iPos+1));"<br>"
|
|
|
|
' Endif
|
|
|
|
' Break
|
|
|
|
' Endif
|
|
|
|
' Next
|
|
|
|
'
|
|
|
|
' Print "</div>"
|
|
|
|
|
2014-11-09 23:06:07 +01:00
|
|
|
If bGambasOnly Then
|
|
|
|
|
|
|
|
For Each cResult In aResult
|
2018-07-03 00:54:34 +02:00
|
|
|
Print cResult!name; Space$(20 - Len(cResult!name)); ": "; Format(cResult!gambas, "0.00"); " / ";Format(cResult!gambasjit, "0.00");" (jit)"; " / ";Format(cResult!gambasjitwct, "0.00");" (jit without compilation time)"
|
2014-11-09 23:06:07 +01:00
|
|
|
Next
|
|
|
|
|
|
|
|
Else
|
|
|
|
|
|
|
|
Print "<table class=\"table\">"
|
|
|
|
Print "<tr>\n<th>Benchmark</th>"
|
2018-07-03 00:54:34 +02:00
|
|
|
For Each sLang In ["Python", "Perl", "Gambas", "Gambas JIT", "Gambas JIT without compilation time"]
|
2014-11-09 23:06:07 +01:00
|
|
|
Print "<th style=\"width:12em;\">"; Html(sLang); "</th>"
|
|
|
|
Next
|
2014-10-31 20:42:59 +01:00
|
|
|
Print "</tr>"
|
2014-11-09 23:06:07 +01:00
|
|
|
For Each cResult In aResult
|
|
|
|
Print "<tr>"
|
|
|
|
Print "<td><tt>"; cResult!name; "</tt></td>"
|
|
|
|
Print "<td align=\"right\">"; FormatResult(cResult, "python"); " </td>"
|
|
|
|
Print "<td align=\"right\">"; FormatResult(cResult, "perl"); " </td>"
|
|
|
|
Print "<td align=\"right\">"; FormatResult(cResult, "gambas"); " </td>"
|
|
|
|
Print "<td align=\"right\">"; Format(cResult!gambasjit, "0.00"); " </td>"
|
2018-07-03 00:54:34 +02:00
|
|
|
Print "<td align=\"right\">"; Format(cResult!gambasjitwct, "0.00"); " </td>"
|
2014-11-09 23:06:07 +01:00
|
|
|
Print "</tr>"
|
|
|
|
Next
|
|
|
|
Print "</table>"
|
|
|
|
|
|
|
|
Endif
|
2014-10-31 17:36:02 +01:00
|
|
|
|