Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
.NET
»
Topic:
TestTimer
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: TestTimer (Read 1470 times)
0 Members and 1 Guest are viewing this topic.
Jeff H
Needs a day job
Posts: 6150
TestTimer
«
on:
October 22, 2012, 12:50:53 PM »
This is a simple but useful idea from Lee Campbell's free ebook
Introduction to Rx
Maybe should add logic for adding in Editor's EnteringQuiescentState event as pointed out by
Spiderinnet1
at
AutoCAD .NET: Real Performance of ObjectId.Open/GetObject Transaction and OpenCloseTransaction
Also adding logic for nesting might be useful?
Code - C#:
[Select]
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Diagnostics
;
using
Autodesk.AutoCAD.EditorInput
;
using
Autodesk.AutoCAD.ApplicationServices.Core
;
namespace
Autodesk
.
AutoCAD
.
Diagnostics
{
/// <summary>
/// Author : Lee Campbell
/// Source : http://www.introtorx.com/
/// Modified to print to AutoCAD console.
/// </summary>
public
class
TestTimer
:
IDisposable
{
private
readonly
string
_name
;
private
readonly
Stopwatch _watch
;
public
TestTimer
(
string
name
)
{
_name
=
name
;
_watch
=
Stopwatch
.
StartNew
(
)
;
}
public
void
Dispose
(
)
{
_watch
.
Stop
(
)
;
Application
.
DocumentManager
.
MdiActiveDocument
.
Editor
.
WriteLine
(
"{0} took {1}"
, _name, _watch
&
#8204;.Elapsed);
}
}
}
Logged
--> Donate to TheSwamp <--
bargool
Guest
Re: TestTimer
«
Reply #1 on:
October 23, 2012, 03:02:13 AM »
Is useful something like this?
Code - C#:
[Select]
public
class
TestTimer
:
IDisposable
{
private
readonly
string
_name
;
private
readonly
Stopwatch _watch
;
private
readonly
Action
<
string
>
_action
;
public
TestTimer
(
string
name
)
{
_name
=
name
;
_watch
=
Stopwatch
.
StartNew
(
)
;
}
public
TestTimer
(
string
name, Action
<
string
>
action
)
:
this
(
name
)
{
_action
=
action
;
}
public
void
Dispose
(
)
{
_watch
.
Stop
(
)
;
string
message
=
string
.
Format
(
"{0} took {1}"
, _name, _watch
.
Elapsed
)
;
if
(
_action
==
null
)
Application
.
DocumentManager
.
MdiActiveDocument
.
Editor
.
WriteMessage
(
"
\n
"
+
message
)
;
else
_action
(
message
)
;
}
}
Code - C#:
[Select]
using
(
TestTimer timer
=
new
TestTimer
(
"Creating 1000 random lines"
, n
=>
log
.
AppendLine
(
n
)
)
)
{
...
}
Logged
Jeff H
Needs a day job
Posts: 6150
Re: TestTimer
«
Reply #2 on:
October 23, 2012, 10:05:57 AM »
Yes Bargool that would be one way.
Logged
--> Donate to TheSwamp <--
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
.NET
»
Topic:
TestTimer