jcunews

script-load-times.vbs

May 20th, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Script to benchmark load time of script interpreter programs:
  2. 'CMD (batch file), Windows Script Host (CSCRIPT; JScript & VBScript),
  3. 'AutoHotkey, and PowerShell.
  4. '
  5. 'Load time is the averate time to execute a test script file 50 times.
  6. 'Test script code is simply to set local variable `a` to text `z`.
  7. '
  8. 'Execute this script using CSCRIPT from the Command Prompt.
  9. '
  10. 'Result on 4-cores Intel i5 2.4GHz, 16GB RAM, Windows 7 SP1 x64,
  11. 'Internet Explorer 11, PowerShell 2.0:
  12. '
  13. 'CMD Batch File average load time: 35.94ms
  14. 'WSH JScript average load time: 49.9ms
  15. 'WSH VBScript average load time: 48.12ms
  16. 'AutoHotkey average load time: 35.48ms
  17. 'PowerShell average load time: 572.7ms
  18. '
  19. 'PowerShell lags behind miserably.
  20.  
  21. testCount = 50
  22. 'name, result, cmdline, ext, code
  23. tests = array( _
  24.   array("CMD Batch File", -1, "c:\windows\system32\cmd.exe /c", "bat", _
  25.     "@set a=z"), _
  26.   array("WSH JScript", -1, "c:\windows\system32\cscript.exe", "js", _
  27.     "a = 'z'"), _
  28.   array("WSH VBScript", -1, "c:\windows\system32\cscript.exe", "vbs", _
  29.     "a = ""z"""), _
  30.   array("AutoHotkey", -1, """c:\program files (x86)\text\autohotkey" & _
  31.     "\autohotkey.exe""", "ahk", "a:= ""z"""), _
  32.   array("PowerShell", -1, "c:\windows\system32\WindowsPowerShell\v1.0" & _
  33.     "\powershell.exe -executionpolicy bypass", "ps1", _
  34.     "set-variable a z" & vbcrlf) _
  35. )
  36. set fs = createobject("scripting.filesystemobject")
  37.  
  38. for each r in tests
  39.   if left(r(2), 1) = """" then
  40.     s = mid(r(2), 2, instr(2, r(2), """") - 2)
  41.   else
  42.     s = left(r(2), instr(r(2), ".exe") + 3)
  43.   end if
  44.   if not fs.fileexists(s) then
  45.     wsh.stdout.writeline "File is not found: " & s
  46.     e = true
  47.   end if
  48. next
  49. if e then wsh.quit
  50.  
  51. set ws = createobject("wscript.shell")
  52. tp = fs.getspecialfolder(2) & "\test."
  53. wsh.stdout.writeline "Script load-times benchmark"
  54.  
  55. for i = 0 to ubound(tests)
  56.   wsh.stdout.writeline
  57.   fn = tp & tests(i)(3)
  58.   set f = fs.createtextfile(fn)
  59.   f.write tests(i)(4)
  60.   f.close
  61.   t = timer
  62.   for j = 1 to testCount
  63.     wsh.stdout.writeline tests(i)(0) & " test " & j & " of " & testCount
  64.     ws.run tests(i)(2) & " """ & fn & """", 0, true
  65.   next
  66.   tests(i)(1) = round(((timer - t) * 1000) / testCount, 3)
  67.   fs.deletefile fn
  68. next
  69.  
  70. wsh.stdout.writeline
  71. for each r in tests
  72.   wsh.stdout.writeline r(0) & " average load time: " & r(1) & "ms"
  73. next
  74.  
Add Comment
Please, Sign In to add comment