![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
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 |
![]() |
![]()
|
![]() |
|
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. |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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. |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
It would be interesting to know the memory usage during these tests too.
|
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Optimizing DXL code
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.