処理時間計測クラス

Namespace: FVIL
Assembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)

Syntax

C#
[SerializableAttribute]
public sealed class CFviTimeCounter : CFviObject
Visual Basic
<SerializableAttribute>
Public NotInheritable Class CFviTimeCounter
	Inherits CFviObject

Remarks

Windows API の QueryPerformanceCounter を用いて時間計測を行います。 高分解能パフォーマンスカウンタがサポートされていないマザーボードでは使用できません。

マルチプロセッサのコンピュータを使っている場合、どのプロセッサを呼び出しても問題はありません。 但し、BIOS または HAL のバグが原因で、異なったプロセッサを呼び出すと、異なった結果を取得する可能性があります。 その場合は、このクラスを使用するスレッドに対して特定のプロセッサを指定する必要があります。

Examples

コード例:

下記のようにして処理時間を計測する事ができます。

C# Copy imageCopy
//    $Revision: 1.2 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace User.SampleCode
{
    public partial class Basic
    {
        /// <summary>
        /// 時間計測 (1)
        /// </summary>
        [FvPluginExecute]
        public void TimeCounter1()
        {
            FVIL.CFviTimeCounter timer = new FVIL.CFviTimeCounter();
            timer.Start();                // 計測開始.

            System.Threading.Thread.Sleep(1000);

            double msec = timer.Stop();    // 計測終了.

            Console.WriteLine("{0:F} msec", msec);
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Namespace SampleCode
    Public Partial Class Basic
        ''' <summary>
        ''' 時間計測 (1)
        ''' </summary>
        <FvPluginExecute> _
        Public Sub TimeCounter1()
            Dim timer As New FVIL.CFviTimeCounter()
            timer.Start()
            ' 計測開始.
            System.Threading.Thread.Sleep(1000)

            Dim msec As Double = timer.[Stop]()
            ' 計測終了.
            Console.WriteLine("{0:F} msec", msec)
        End Sub
    End Class
End Namespace

実行結果:
999.46 msec
※ Sleep 関数の誤差があるので、計測値は 1000 にはならない場合があります。


コード例: GetTime(true)

連続して計測する場合に、GetTime()()()() メソッドを使用して計測の誤差を減らす事ができます。 引数の true は、計測開始時間をリセットする事を意味します。

C# Copy imageCopy
//    $Revision: 1.2 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace User.SampleCode
{
    public partial class Basic
    {
        /// <summary>
        /// 時間計測 (2)
        /// </summary>
        [FvPluginExecute]
        public void TimeCounter2()
        {
            FVIL.CFviTimeCounter timer = new FVIL.CFviTimeCounter();
            double msec1, msec2;
            timer.Start();                    // 計測開始.

            System.Threading.Thread.Sleep(2000);
            msec1 = timer.GetTime(true);    // 1つ目の計測.

            System.Threading.Thread.Sleep(3000);
            msec2 = timer.GetTime(true);    // 2つ目の計測.

            Console.WriteLine("1: {0} msec", msec1.ToString("#.000"));
            Console.WriteLine("2: {0} msec", msec2.ToString("#.000"));
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Namespace SampleCode
    Public Partial Class Basic
        ''' <summary>
        ''' 時間計測 (2)
        ''' </summary>
        <FvPluginExecute> _
        Public Sub TimeCounter2()
            Dim timer As New FVIL.CFviTimeCounter()
            Dim msec1 As Double, msec2 As Double
            timer.Start()
            ' 計測開始.
            System.Threading.Thread.Sleep(2000)
            msec1 = timer.GetTime(True)
            ' 1つ目の計測.
            System.Threading.Thread.Sleep(3000)
            msec2 = timer.GetTime(True)
            ' 2つ目の計測.
            Console.WriteLine("1: {0} msec", msec1.ToString("#.000"))
            Console.WriteLine("2: {0} msec", msec2.ToString("#.000"))
        End Sub
    End Class
End Namespace

実行結果:
1: 1999.466 msec
2: 2999.743 msec



コード例: GetTime(false)

GetTime()()()() の引数に false を指定すると、計測開始時間を保持します。Stop()()()() を使用した場合と等価です。

C# Copy imageCopy
//    $Revision: 1.2 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace User.SampleCode
{
    public partial class Basic
    {
        /// <summary>
        /// 時間計測 (3)
        /// </summary>
        [FvPluginExecute]
        public void TimeCounter3()
        {
            FVIL.CFviTimeCounter timer = new FVIL.CFviTimeCounter();
            double msec1, msec2, msec3;
            timer.Start();                    // 計測開始.

            System.Threading.Thread.Sleep(2000);
            msec1 = timer.GetTime(false);    // 1つ目の計測.

            System.Threading.Thread.Sleep(300);
            msec2 = timer.GetTime(false);    // 2つ目の計測.

            System.Threading.Thread.Sleep(10);
            msec3 = timer.GetTime(false);    // 3つ目の計測.

            Console.WriteLine("1: {0} msec", msec1.ToString("#.000"));
            Console.WriteLine("2: {0} msec", msec2.ToString("#.000"));
            Console.WriteLine("3: {0} msec", msec3.ToString("#.000"));
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Namespace SampleCode
    Public Partial Class Basic
        ''' <summary>
        ''' 時間計測 (3)
        ''' </summary>
        <FvPluginExecute> _
        Public Sub TimeCounter3()
            Dim timer As New FVIL.CFviTimeCounter()
            Dim msec1 As Double, msec2 As Double, msec3 As Double
            timer.Start()
            ' 計測開始.
            System.Threading.Thread.Sleep(2000)
            msec1 = timer.GetTime(False)
            ' 1つ目の計測.
            System.Threading.Thread.Sleep(300)
            msec2 = timer.GetTime(False)
            ' 2つ目の計測.
            System.Threading.Thread.Sleep(10)
            msec3 = timer.GetTime(False)
            ' 3つ目の計測.
            Console.WriteLine("1: {0} msec", msec1.ToString("#.000"))
            Console.WriteLine("2: {0} msec", msec2.ToString("#.000"))
            Console.WriteLine("3: {0} msec", msec3.ToString("#.000"))
        End Sub
    End Class
End Namespace

実行結果:
1: 2000.023 msec
2: 2300.812 msec
3: 2311.549 msec

Inheritance Hierarchy

System..::..Object
FVIL..::..CFviObject
FVIL..::..CFviTimeCounter

See Also