閲覧総計:&counter(); (本日:&counter(today); 昨日:&counter(yesterday);) プログラムを作成していると「これ処理が遅いなあ。どこの処理にどれくらいの時間 が掛かっているんだろう?」とコードの処理時間を計測したいニーズが発生します。 コードの処理時間を計測する方法 Stopwatchクラスの使用法を確認したのでメモを 残しておきます。 10/09/04 【参考にしたページ】 http://www.atmarkit.co.jp/fdotnet/dotnettips/412stopwatch/stopwatch.html 開発環境:VWD2008 + Access2003 サーバ:ASP.NET3.5 + Access2003 【実行画面】 #ref(stopwatch稼働画面.jpg); 【Stopwatch.aspx】 <%@ Page Language="VB" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Diagnostics" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <script runat="server"> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim sw As New Stopwatch sw.Start() System.Threading.Thread.Sleep(1000) sw.Stop() ' ミリ秒単位で出力 Dim millisec As Long = sw.ElapsedMilliseconds Label1.Text = millisec ' 出力例:998 ' TimeSpan構造体で書式付き表示 Dim ts As TimeSpan = sw.Elapsed Label2.Text = ts.ToString ' 出力例:00:00:00.9984668 End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> コード実行時間を計測するStopwatch機能の使用法の確認 10/08/31<br /> ↓参考ページ<br /> <a href="http://www.atmarkit.co.jp/fdotnet/dotnettips/412stopwatch/stopwatch.html"> http://www.atmarkit.co.jp/fdotnet/dotnettips/412stopwatch/stopwatch.html</a><br /> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="実行時間計測" /> <br /> <br /> 実行時間(ミリ秒表示):<asp:Label ID="Label1" runat="server" Text="???"></asp:Label> ミリ秒<br /> <br /> 実行時間(時分秒表示):<asp:Label ID="Label2" runat="server" Text="???"></asp:Label> <br /> </div> </form> </body> </html> 【参考にしたページ】 http://www.atmarkit.co.jp/fdotnet/dotnettips/412stopwatch/stopwatch.html #comment_nospam #vote(参考になった[0],ふつう[0],参考にならなかった[0])