TechNet
Products
IT Resources
Downloads
Training
Support
Products
Windows
Windows Server
System Center
Microsoft Edge
Office
Office 365
Exchange Server
SQL Server
SharePoint Products
Skype for Business
See all products »
Resources
Channel 9 Video
Evaluation Center
Learning Resources
Microsoft Tech Companion App
Microsoft Technical Communities
Microsoft Virtual Academy
Script Center
Server and Tools Blogs
TechNet Blogs
TechNet Flash Newsletter
TechNet Gallery
TechNet Library
TechNet Magazine
TechNet Wiki
Windows Sysinternals
Virtual Labs
Solutions
Networking
Cloud and Datacenter
Security
Virtualization
Updates
Service Packs
Security Bulletins
Windows Update
Trials
Windows Server 2016
System Center 2016
Windows 10 Enterprise
SQL Server 2016
See all trials »
Related Sites
Microsoft Download Center
Microsoft Evaluation Center
Drivers
Windows Sysinternals
TechNet Gallery
Training
Expert-led, virtual classes
Training Catalog
Class Locator
Microsoft Virtual Academy
Free Windows Server 2012 courses
Free Windows 8 courses
SQL Server training
Microsoft Official Courses On-Demand
Certifications
Certification overview
Special offers
MCSE Cloud Platform and Infrastructure
MCSE: Mobility
MCSE: Data Management and Analytics
MCSE Productivity
Other resources
Microsoft Events
Exam Replay
Born To Learn blog
Find technical communities in your area
Azure training
Official Practice Tests
Support options
For business
For developers
For IT professionals
For technical support
Support offerings
More support
Microsoft Premier Online
TechNet Forums
MSDN Forums
Security Bulletins & Advisories
Not an IT pro?
Microsoft Customer Support
Microsoft Community Forums
Sign in
Home
Library
Wiki
Learn
Gallery
Downloads
Support
Forums
Blogs
Resources For IT Professionals
United States (English)
Россия (Pусский)
中国(简体中文)
Brasil (Português)
Skip to locale bar
Post an article
Translate this page
Powered by
Microsoft® Translator
Wikis - Page Details
First published by
Craig Landis
(Microsoft)
When:
26 Mar 2010 7:03 PM
Last revision by
Edward van Biljon
(MVP, Microsoft Community Contributor)
When:
7 Oct 2016 8:27 AM
Revisions:
9
Comments:
2
Options
Subscribe to Article (RSS)
Share this
Engage!
Wiki Ninjas Blog
(
Announcements
)
Wiki Ninjas on Twitter
TechNet Wiki Discussion Forum
Can You Improve This Article?
Positively!
Click Sign In to add the tip, solution, correction or comment that will help other users.
Report inappropriate content using
these instructions
.
Wiki
>
TechNet Articles
>
VBScript: Determine Script Execution Time
VBScript: Determine Script Execution Time
Article
History
VBScript: Determine Script Execution Time
To output a script's execution time, include this at the beginning:
dtmStartTime = Timer
And include this at the end:
Wscript.Echo "Script execution time: " & Round(Timer - dtmStartTime, 2) & " seconds"
The
Timer
function returns the number of seconds that have elapsed since midnight (12:00 a.m.). The
Round
function controls the number of decimal places displayed.
Here is a function that will convert seconds to days, hours, and minutes.
Function GetElapsedTime
Const SECONDS_IN_DAY = 86400
Const SECONDS_IN_HOUR = 3600
Const SECONDS_IN_MINUTE = 60
Const SECONDS_IN_WEEK = 604800
dtmEndTime = Timer
seconds = Round(dtmEndTime - dtmStartTime, 2)
If seconds < SECONDS_IN_MINUTE Then
GetElapsedTime = seconds & " seconds "
Exit Function
End If
If seconds < SECONDS_IN_HOUR Then
minutes = seconds / SECONDS_IN_MINUTE
seconds = seconds MOD SECONDS_IN_MINUTE
GetElapsedTime = Int(minutes) & " minutes " & seconds & " seconds "
Exit Function
End If
If seconds < SECONDS_IN_DAY Then
hours = seconds / SECONDS_IN_HOUR
minutes = (seconds MOD SECONDS_IN_HOUR) / SECONDS_IN_MINUTE
seconds = (seconds MOD SECONDS_IN_HOUR) MOD SECONDS_IN_MINUTE
GetElapsedTime = Int(hours) & " hours " & Int(minutes) & " minutes " & seconds & " seconds "
Exit Function
End If
If seconds < SECONDS_IN_WEEK Then
days = seconds / SECONDS_IN_DAY
hours = (seconds MOD SECONDS_IN_DAY) / SECONDS_IN_HOUR
minutes = ((seconds MOD SECONDS_IN_DAY) MOD SECONDS_IN_HOUR) / SECONDS_IN_MINUTE
seconds = ((seconds MOD SECONDS_IN_DAY) MOD SECONDS_IN_HOUR) MOD SECONDS_IN_MINUTE
GetElapsedTime = Int(days) & " days " & Int(hours) & " hours " & Int(minutes) & " minutes " & seconds & " seconds "
Exit Function
End If
End Function
Here is a sample script using the function that prints "Hello World!" to the screen, waits for 1 second, then outputs the script execution time.
dtmStartTime = Timer
Wscript.Echo "Hello, World!"
Wscript.Sleep 1000
Wscript.Echo "Script completed in " & GetElapsedTime
Function GetElapsedTime
Const SECONDS_IN_DAY = 86400
Const SECONDS_IN_HOUR = 3600
Const SECONDS_IN_MINUTE = 60
Const SECONDS_IN_WEEK = 604800
dtmEndTime = Timer
seconds = Round(dtmEndTime - dtmStartTime, 2)
If seconds < SECONDS_IN_MINUTE Then
GetElapsedTime = seconds & " seconds "
Exit Function
End If
If seconds < SECONDS_IN_HOUR Then
minutes = seconds / SECONDS_IN_MINUTE
seconds = seconds MOD SECONDS_IN_MINUTE
GetElapsedTime = Int(minutes) & " minutes " & seconds & " seconds "
Exit Function
End If
If seconds < SECONDS_IN_DAY Then
hours = seconds / SECONDS_IN_HOUR
minutes = (seconds MOD SECONDS_IN_HOUR) / SECONDS_IN_MINUTE
seconds = (seconds MOD SECONDS_IN_HOUR) MOD SECONDS_IN_MINUTE
GetElapsedTime = Int(hours) & " hours " & Int(minutes) & " minutes " & seconds & " seconds "
Exit Function
End If
If seconds < SECONDS_IN_WEEK Then
days = seconds / SECONDS_IN_DAY
hours = (seconds MOD SECONDS_IN_DAY) / SECONDS_IN_HOUR
minutes = ((seconds MOD SECONDS_IN_DAY) MOD SECONDS_IN_HOUR) / SECONDS_IN_MINUTE
seconds = ((seconds MOD SECONDS_IN_DAY) MOD SECONDS_IN_HOUR) MOD SECONDS_IN_MINUTE
GetElapsedTime = Int(days) & " days " & Int(hours) & " hours " & Int(minutes) & " minutes " & seconds & " seconds "
Exit Function
End If
End Function