Pages

9/30/2014

Test time to open Word documents of various sizes

Goal: Test to gather the time to open and save various size documents

function sleep(milliseconds) {
 var start = new Date().getTime();
 for (var i = 0; i < 1e7; i++) {
  if ((new Date().getTime() - start) > milliseconds){
   break;
   }
  }
 }

var myApp = new ActiveXObject("Word.Application");
myApp.Visible = true;

// Open 200K
var smopenstart = new Date().getTime();
  myApp.Documents.Open("Z:\\200K.doc");
var smopenend = new Date().getTime();

//wait 10 s
sleep(10000);

// Save 200K
var smsavestart = new Date().getTime();
  myApp.ActiveDocument.SaveAs("Z:\\NEW\\200K.doc");
var smsaveend = new Date().getTime();

// Close 200K
myApp.Documents.Close();

//quit Word
myApp.Application.Quit();

//wait 10 s
sleep(10000);

var myApp = new ActiveXObject("Word.Application");
myApp.Visible = true;

// Open 1MB
var medopenstart = new Date().getTime();
  myApp.Documents.Open("Z:\\1M.doc");
var medopenend = new Date().getTime();

//wait 10 s
sleep(10000);

// Save 1MB
var medsavestart = new Date().getTime();
  myApp.ActiveDocument.SaveAs("Z:\\NEW\\1M.doc");
var medsaveend = new Date().getTime();

// Close 1MB
myApp.Documents.Close();

//quit Word
myApp.Application.Quit();


//wait 10 s
sleep(10000);

var myApp = new ActiveXObject("Word.Application");
myApp.Visible = true;

// Open 5MB
var lrgopenstart = new Date().getTime();
  myApp.Documents.Open("Z:\\5M.doc");
var lrgopenend = new Date().getTime();

//wait 10 s
sleep(10000);

// Save 5MB
var lrgsavestart = new Date().getTime();
  myApp.ActiveDocument.SaveAs("Z:\\NEW\\5M.doc");
var lrgsaveend = new Date().getTime();

// Close 5MB
myApp.Documents.Close();

//quit Word
myApp.Application.Quit();

//define date string
var mo = new Date().getMonth()+1;
if (mo < 10) { mo = "0" + mo };
var day = new Date().getDate();
if (day < 10) {day = "0" + day};
var year = new Date().getFullYear();
var hrs = new Date().getHours();
if (hrs < 10) {hrs = "0" + hrs};
var m = new Date().getMinutes();
if (m < 10) {m = "0" + m};
var s = new Date().getSeconds();
if (s < 10) {s = "0" + s};
var dt = mo + "/" + day + "/" + year + " " + hrs + ":" + m + ":" + s

//Calculate times
var smopentime = (smopenend - smopenstart)/1000
var smsavetime = (smsaveend - smsavestart)/1000
var medopentime = (medopenend - medopenstart)/1000
var medsavetime = (medsaveend - medsavestart)/1000
var lrgopentime = (lrgopenend - lrgopenstart)/1000
var lrgsavetime = (lrgsaveend - lrgsavestart)/1000

//output results
WScript.Echo(dt, ",", smopentime, ",", smsavetime, ",", medopentime, ",", medsavetime, ",", lrgopentime, ",", lrgsavetime);
Save above as "openword.js" and call with the following BAT file

net use Z: \\SHARE\TEST\ATL
c:
cd\temp
cscript //NoLogo c:\temp\openword.js >> CHI.log
echo y | del z:\new\*.*
net use z: /delete

No comments: