#!/usr/bin/env gbs3 Private Sub RunScript(sScript As String, sRun As String) As Float Dim sResult As String Dim fTime As Float Print "" Shell "/usr/bin/time -v " & sRun & " " & sScript & " 2>&1 >/dev/null" To sResult If Not sResult Then Error.Raise("Script '" & sRun & " " & sScript & "' failed!") For Each sResult in Split(sResult, "\n") sResult = Trim(sResult) If sResult Begins "User time" Or If sResult Begins "System time" Then fTime += CFloat(Mid$(sResult, Instr(sResult, ":") + 2)) Endif Next 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 For Each sBenchmark In Dir(Application.Dir, "*.gbs") sBenchmark = File.BaseName(sBenchmark) If sBenchmark = "benchmark" Then Continue If Args[1] And If sBenchmark <> Args[1] Then Continue cResult = New Collection aResult.Add(cResult) cResult!name = sBenchmark cResult!gambasjit = RunScript(sBenchmark & ".gbs", "gbs3 -f -c") cResult!gambas = RunScript(sBenchmark & ".gbs", "gbs3 -c") cResult!python = RunScript(sBenchmark & ".py", "python") cResult!perl = RunScript(sBenchmark & ".pl", "perl") Next ' Print "
Benchmark | " For Each sLang In ["Python","Perl","Gambas","Gambas + JIT"] Print ""; Html(sLang);" | " Next Print "|||
---|---|---|---|---|
";cResult!name; " | " Print ""; FormatResult(cResult, "python");" | " Print ""; FormatResult(cResult, "perl");" | " Print ""; FormatResult(cResult, "gambas");" | " Print ""; Format(cResult!gambasjit, "0.00");" | " Print "