Array performance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • guy

    #1

    Array performance

    from using FxCop and reading MSDN i understand that i should not use properties to access arrays, i should use methods instead,
    however when i try the code below the MSIL for method and property access is identical, bar a slight differenc in code size and stack size.
    What is the correct way to access an array, given that i need to perform actions on sections of the array as well as individual elements. Do I just access it directly? (in my actual app the array is 2 dimensional, approx 64k elements)

    sample code:-
    Private _a(100) As Integer
    Public Property a() As Integer()
    Get
    Return _a
    End Get
    Set(ByVal Value() As Integer)
    _a = Value
    End Set
    End Property
    Public Function GetA() As Integer()
    Return _a
    End Function
    Public Function SetA(ByVal x() As Integer) As Integer()
    _a = x
    End Function
  • Cor Ligthert

    #2
    Re: Array performance

    Hi guy,

    To test those things you can just set it in a loop than you know the
    difference, not with a single

    As timer you can take
    dim start as integer = environment.tic kcount
    your process
    dim endtime as integer = environment.tic kcount - start

    Cor
    [color=blue]
    > from using FxCop and reading MSDN i understand that i should not use[/color]
    properties to access arrays, i should use methods instead,[color=blue]
    > however when i try the code below the MSIL for method and property access[/color]
    is identical, bar a slight differenc in code size and stack size.[color=blue]
    > What is the correct way to access an array, given that i need to perform[/color]
    actions on sections of the array as well as individual elements. Do I just
    access it directly? (in my actual app the array is 2 dimensional, approx
    64k elements)[color=blue]
    >
    > sample code:-
    > Private _a(100) As Integer
    > Public Property a() As Integer()
    > Get
    > Return _a
    > End Get
    > Set(ByVal Value() As Integer)
    > _a = Value
    > End Set
    > End Property
    > Public Function GetA() As Integer()
    > Return _a
    > End Function
    > Public Function SetA(ByVal x() As Integer) As Integer()
    > _a = x
    > End Function[/color]


    Comment

    • Cor Ligthert

      #3
      Re: Array performance

      Hi Guy,

      What do you want to archieve in my opinon are you only passing a complete
      array in all your samples, is that what you want to archieve?

      So the time difference will me minimal between a method and a property

      Cor


      Comment

      • guy

        #4
        Re: Array performance

        Hi Cor,
        I need to perform processing on individual elements, for which a method would be fine, however I also need to do things like shifting blocks of elements up or down the array

        Looks like I will just have to process the array directly

        thanks

        guy

        "Cor Ligthert" wrote:
        [color=blue]
        > Hi Guy,
        >
        > What do you want to archieve in my opinon are you only passing a complete
        > array in all your samples, is that what you want to archieve?
        >
        > So the time difference will me minimal between a method and a property
        >
        > Cor
        >
        >
        >[/color]

        Comment

        • Cor Ligthert

          #5
          Re: Array performance

          Hi Guy,

          And why do you not use the standard arrays as the arraylist, hashtable,
          sortedlist and more of those?

          Cor


          Comment

          • guy

            #6
            Re: Array performance

            Hi Cor,
            I actually need to process a 2D array approx(300,200)
            so 60K elements , which are 4 byte strucures. In the course of a run a very rough estimate is 60K*60K*2 accesses ie 7,200,000,000
            plus 30K array shifts so i need real performance!
            there is virtuallt no other processing, just array crunching

            guy

            "Cor Ligthert" wrote:
            [color=blue]
            > Hi Guy,
            >
            > And why do you not use the standard arrays as the arraylist, hashtable,
            > sortedlist and more of those?
            >
            > Cor
            >
            >
            >[/color]

            Comment

            • Cor Ligthert

              #7
              Re: Array performance

              Hi Guy,

              Fixed or not Fixed?
              With what I mean do you know in advance the size of it?

              Cor

              "guy" <guy@discussion s.microsoft.com > schreef in bericht
              news:115643F8-4496-4A25-AA26-0EC0EE077564@mi crosoft.com...[color=blue]
              > Hi Cor,
              > I actually need to process a 2D array approx(300,200)
              > so 60K elements , which are 4 byte strucures. In the course of a run a[/color]
              very rough estimate is 60K*60K*2 accesses ie 7,200,000,000[color=blue]
              > plus 30K array shifts so i need real performance!
              > there is virtuallt no other processing, just array crunching
              >
              > guy
              >
              > "Cor Ligthert" wrote:
              >[color=green]
              > > Hi Guy,
              > >
              > > And why do you not use the standard arrays as the arraylist, hashtable,
              > > sortedlist and more of those?
              > >
              > > Cor
              > >
              > >
              > >[/color][/color]


              Comment

              • Cor Ligthert

                #8
                Re: Array performance

                Hi Guy,

                Go over to the language vb , I think that this needs a wider discussion than
                only my opinion.

                microsoft.publi c.dotnet.langua ges.vb

                I agree it is not only language, however there you get more opinions.

                (That is not that I will nog give my idea about this in that newsgroup,
                however I think it is good to have in this huge array more opinions.)

                Cor


                Comment

                Working...