Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Optimizing DXL code
Topic Summary: How to identifiy slow parts of code?
Created On: 17-Jun-2008 16:18
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 17-Jun-2008 16:18
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Specifically, I'm looking for ways to add some debugging code to my DXL functions which will report back some kind of timing data, which I can then use to identify slow parts, and work on faster methods.

I have some larger functions which can take a while to run. I am sure my code is probably not optimal. Some of my functions loop through all objects in a module, do a bunch of operations on buffers, tally up statistics, etc., etc. I'd like to instrument my code in a way where I can get detailed timing data on the various steps in these functions. Then, I can identify the slow parts of the functions and work on more optimal methods, and make these functions run faster.

My current method is something like

xTimer = intOf(today)
// do some steps
xElapsed = intOf(today) - xTimer
// Report xElapsed time

The problem is, this is not that accurate as it can only count whole seconds. I did learn there is an undocumented "sleep_(milliseconds)" function, but this simply waits, and does not provide a way to report back the delayed time.
Report this to a Moderator Report this to a Moderator
 17-Jun-2008 16:36
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

You might want to look at undocument function win32SystemWait_

and either dos command time or some other dos based utility you can find on the web
Report this to a Moderator Report this to a Moderator
 17-Jun-2008 17:28
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Instead of intOf(today) (seconds) you could use "getTickCount_", which returns the miili-seconds since you logged into your computer.

You will find that that DOORS slows down the longer it runs, that is your function A may take a half second early in the run but slow down to 10 seconds much later in the run. This is mostly due, I believe, string table memory wasting and searching.

- Louie
Report this to a Moderator Report this to a Moderator
 17-Jun-2008 18:05
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Thanks Louie, I will try getTickCount_.

I agree that one issue seems to be with string table "build up". It seems to me that, even if you have just a few short strings, that if those strings are defined locally within sub-functions and/or passed back and forth between functions, and then you call those functions several times (god forbid in a large loop) that DOORS keeps some sort of history of all the strings and never really releases any of them.

For example:
int i
void ackString() {string temp = "Hello World";print temp}
for(i=0;i<1000;i++) {ackString}

I think DOORS essentially creates 1000 copies of "Hello World" in memory.

I've also learned that, while the use of Buffers instead of strings can help with memory management in some cases, you have to very careful what functions you use on Buffers. Matching regular expressions and sub-string extraction from Buffers can be very slow and inefficient.

I seem to have a constant battle of tyring ot avoid gobbling up all available RAM and CPU time.
Report this to a Moderator Report this to a Moderator
 17-Jun-2008 20:03
User is offline View Users Profile Print this message


Pete Kowalski

Posts: 301
Joined: 7-Feb-2003

In addition to these ideas, you can also perform some old-fashion run time analysis to analyze your algorithms ensuring that you have efficient code.

http://en.wikipedia.org/wiki/Big_O_notation

http://en.wikipedia.org/wiki/Run-time_analysis

-------------------------
pete.kowalski(at)motorola.com
Report this to a Moderator Report this to a Moderator
 17-Jun-2008 20:07
User is offline View Users Profile Print this message


Scott Boisvert

Posts: 348
Joined: 14-Apr-2006

O, how I loathe Big O notation.

I hated that part of Discrete Math.

-------------------------
Scott Boisvert
Engineering Tools Administrator
L-3 Communications - Avionics Systems
scott.boisvert@l-3com.com
Report this to a Moderator Report this to a Moderator
 18-Jun-2008 19:43
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

Following code illustrates some characteristics of execution time in DXL

//testoftime
/* demo Shows that:
-- Globals may not be faster
-- Buffer may be faster
-- Dialog boxes may be faster than print
*/
pragma runLim, 0
int i
int t
int total, t1, total2, total3, total4
string temp2
Buffer b = create
temp2 = "Hello World "
DB mainDB = create ""
int iTerations = 10000

void ackString() { string temp = "Hello World ";print temp}
void ackString2() { print temp2}
void ackString3() { b+= "Hello World "}
void ackString4() { b+= "Hello World "}

t =getTickCount_
for(i=0;i<iTerations;i++) {ackString}
t1 =getTickCount_
total= t1 - t

t =getTickCount_
for(i=0;i<iTerations;i++) {ackString2}
t1 =getTickCount_
total2= t1 - t

t =getTickCount_
for(i=0;i<iTerations;i++) {ackString3}
print b""
t1 =getTickCount_
total3= t1 - t
b=""

t =getTickCount_
for(i=0;i<iTerations;i++) {ackString4}
text(mainDB,"", b"",200, false)
realize mainDB
t1 =getTickCount_
total4= t1 - t

print "\n\nLocal variable time =" total ""
print "; Global String time2 =" total2 ""
print "; Buffer time3 with print =" total3 ""
print "; Buffer time4 with dialog =" total4 ""
//example print out: Local variable time =87610; Global String time2 =253296; Buffer time3 with print =79; Buffer time4 with dialog =31
Report this to a Moderator Report this to a Moderator
 18-Jun-2008 22:15
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

print statements take a long time; in fact take increasingly longer the more print statements you have. I'd be surprised if you swapped execution of ackString with ackString 2, that your results would be similar; global would be 'fast' and local would be 'slow'.

- Louie
Report this to a Moderator Report this to a Moderator
 19-Jun-2008 10:17
User is offline View Users Profile Print this message


Tony Goodman

Posts: 97
Joined: 6-May-2008

Louie is correct, prints take ages!

If you want to print stuff out, accumulate all the strings in a buffer and call print once at the end of the script.

-------------------------
Tony Goodman
Smart DXL limited
www.smartdxl.com
Report this to a Moderator Report this to a Moderator
 19-Jun-2008 19:36
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

It would be interesting to know the memory usage during these tests too.
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.