#!/usr/bin/env gbs3 Private $fCompileTime as Float Private Sub RunScript(sScript As String, sRun As String, bGambasOnly As Boolean) As Float Dim aResult as String[] Dim sResult As String Dim fTime As Float If bGambasOnly Then Print "Running benchmark: '"; sRun; " "; sScript; "'" Else Print "" Endif Shell "/usr/bin/time -v " & sRun & " " & sScript & " 2>&1 >/dev/null" To sResult If Not sResult Then Error.Raise("Script '" & sRun & " " & sScript & "' failed!") aResult = Split(sResult, "\n") For Each sResult In aResult sResult = Trim(sResult) If sResult Begins "User time" Or If sResult Begins "System time" Then fTime += CFloat(Mid$(sResult, InStr(sResult, ":") + 2)) Endif Next $fCompileTime = 0 Try $fCompileTime = CFloat(Trim(aResult[0])) Return fTime End Private Sub FormatResult(cResult As Collection, sLang As String) As String Dim bBetter As Boolean = True Dim sFormat As String Dim sTest As String For Each sTest In ["python", "perl", "gambas"] If cResult[sTest] < cResult[sLang] Then bBetter = False Break Endif Next sFormat = Format(cResult[sLang], "0.00") If bBetter Then sFormat = "" & sFormat & "" Return sFormat End Dim sBenchmark As String Dim cResult As Collection Dim aResult As New Collection[] Dim sLang As String Dim sResult As String Dim iPos As Integer 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 For Each sBenchmark In Dir(Application.Dir, "*.gbs") sBenchmark = File.BaseName(sBenchmark) If sBenchmark = "benchmark" Then Continue If sBenchmarkOnly And If sBenchmark <> sBenchmarkOnly Then Continue cResult = New Collection aResult.Add(cResult) cResult!name = sBenchmark If Not bGambasOnly Then cResult!python = RunScript(sBenchmark & ".py", "python", bGambasOnly) If Not bGambasOnly Then cResult!perl = RunScript(sBenchmark & ".pl", "perl", bGambasOnly) cResult!gambasjit = RunScript(sBenchmark & ".gbs", "gbs3 -f -U -c", bGambasOnly) cResult!gambasjitwct = cResult!gambasjit - $fCompileTime cResult!gambas = RunScript(sBenchmark & ".gbs", "gbs3 -c", bGambasOnly) Next ' Print "
" ' ' Exec ["uname", "-srv"] To sResult ' Print "Kernel: ";Html(sResult);"
" ' ' 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 "CPU: ";Html(Mid$(sResult, iPos+1));"
" ' Endif ' Break ' Endif ' Next ' ' Print "
" If bGambasOnly Then For Each cResult In aResult 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)" Next Else Print "" Print "\n" For Each sLang In ["Python", "Perl", "Gambas", "Gambas JIT", "Gambas JIT without compilation time"] Print "" Next Print "" For Each cResult In aResult Print "" Print "" Print "" Print "" Print "" Print "" Print "" Print "" Next Print "
Benchmark"; Html(sLang); "
"; cResult!name; ""; FormatResult(cResult, "python"); " "; FormatResult(cResult, "perl"); " "; FormatResult(cResult, "gambas"); " "; Format(cResult!gambasjit, "0.00"); " "; Format(cResult!gambasjitwct, "0.00"); " 
" Endif