Macro running time is wrong (sometimes)

Programming and macros
User avatar
mp3-250
Posts: 613
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 656
x 326

Macro running time is wrong (sometimes)

Unread post by mp3-250 »

I am trying to benchmark in a reliable way SOLIDWORKS to compare some modification we perform on assembly components and measure their impact on performance. I am trying to get a macro running time using the timer function before and after I launch a command.

like this pseudocode

Code: Select all

starttime1 = timer
openfile(filename )
endtime1 = timer - starttime

starttime2 = timer
generatedrawing(filename)
endtime2 = timer - starttime
Sometimes I noticed the time recorded is just unreliable and could be off even 50+ seconds.
I am testing my VBA macro with a file that takes around 60s to fully load and 120s to generate 4 views in our drawing template.
For the drawing part I am aware that the view rebuild/update works in multithreading so my macro timer is probably going to stop well before the completion of the drawing and it is likely limited to SW main thread, leaving the view generation processes in background.
by mp3-250 » Tue Aug 27, 2024 5:25 am
I looked around the web and it seems the timer function is just low priority and in case the CPU is very busy it could lag behind.

It seems like my macro was asking the cpu too many things at once: I added some Doevents and the macro runs a lot smoother being able to begin a task before starying another.

E.g. when I inserted our drawing template the macro switched immediately to the main 3 views generation, but most of the time the screen was freezed on SW 3D: I noticed that in rare occasions the drawing sheet was visualized and the total running time was shorter.

I added a Doevents after inserting the template, in this way SW was able to "take a breath", switching to drafting mode, insert the template and, only at that time, starting the view generation tasks.
Go to full post
User avatar
mp3-250
Posts: 613
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 656
x 326

Re: Macro running time is wrong (sometimes)

Unread post by mp3-250 »

I looked around the web and it seems the timer function is just low priority and in case the CPU is very busy it could lag behind.

It seems like my macro was asking the cpu too many things at once: I added some Doevents and the macro runs a lot smoother being able to begin a task before starying another.

E.g. when I inserted our drawing template the macro switched immediately to the main 3 views generation, but most of the time the screen was freezed on SW 3D: I noticed that in rare occasions the drawing sheet was visualized and the total running time was shorter.

I added a Doevents after inserting the template, in this way SW was able to "take a breath", switching to drafting mode, insert the template and, only at that time, starting the view generation tasks.
User avatar
SPerman
Posts: 1975
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2148
x 1796
Contact:

Re: Macro running time is wrong (sometimes)

Unread post by SPerman »

I think it is possible to use Windbg, or DebugView to trace the specific process. Unfortunately I am not familiar enough with these tools to tell you how.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Post Reply