Jump to content

Recommended Posts

  • Moderators

I recently revisited the console object, available in all browsers, and discovered some newbies I didn't know about. The methods and properties below may be sometimes useful for debugging purposes.

The console object is tied to the global window object, so access either by


or define a reference to the window object :

var window   external 'window':   variant;
and call like 

Some console methods are wrapped in SmartCL.System (like writeln ea) and SmartCL.Console

The console.dirxml() above gives an xml representation of any object, which is way better than the 'object Object' result of a console.log(some object) instruction

For performance testing, console also offers native timers

  • console.time()
  • console.timeLog()
  • console.timeEnd()

The above respectively initiate, report and destroy a named timer. The maximum nr of concurrent timers is 10,000 (!)

To see how this works I created a stock new visual project with a single form and no visual controls. 
A timer was inserted at the beginning of the generated js projectfile, at the initialization of the form and at the ApplicationStarting, InitializeForm, InitializeObject and Resize events. Results :

top of main.js :       0.0009765625   ms
Initialization        10.574951171875 ms
applicationstarting   17.234130859375 ms
InitializeObject      21.23095703125  ms
ReSize                62.385986328125 ms
ReSize               101.25           ms
InitializeForm       225.994140625    ms
ReSize               226.757080078125 ms

Wondering about the multiple ReSize calls and the relatively large time lag between InitializeObject and InitializeForm.

There is another feature built into browsers re performance : the window.performance object with its own api's

The most useful methods of this object are performance.now(), which gives a high res timestamp, and performance.toJSON() which gives a json representation of the attributes of the performance object

Below the 'console.timer' and 'performance.now' results of a minimum project with 1 form and no visual controls in the native framework : 

                       console.timeLog      performance.now()               
top of main.js :       0.001953125   ms  /  118.28000005334616 timestamps
Initialization         2.16186523437 ms  /  120.43999996967614
InitializeForm         3.61083984375 ms  /  121.92000006325543
InitializeObject       4.32080078125 ms  /  122.65000003390014

and some values for the attributes of the performance object itself (console.log(window.JSON.stringify(window.performance.toJSON()));)

timeOrigin :               1564383720413.3972  timestamps
navigationStart:           1564383720413
redirectStart:             0
redirectEnd:               0
fetchStart:                1564383720414
domainLookupStart:         1564383720418
domainLookupEnd:           1564383720418
connectStart:              1564383720418
connectEnd:                1564383720418
secureConnectionStart:     0
requestStart:              1564383720418
responseStart:             1564383720423
responseEnd:               1564383720426
unloadEventStart:          1564383720432
unloadEventEnd:            1564383720432
domLoading:                1564383720435
domInteractive:            0
domContentLoadedEventEnd:  0
domComplete:               0
loadEventStart:            0
loadEventEnd:              0


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...