Why is this code so slow?

 

Results 1 to 3 of 3
Code: Dim num As Integer = DataSet1.Tables(0).Rows.Count - 1 Dim no As String = "No" ...
  1. #1
    tb303's Avatar
    tb303 is offline Regular Member
    Join Date
    Dec 2011
    Posts
    443
    Thanks
    199
    Thanked 119 Times in 83 Posts

    Default Why is this code so slow?

    Code:
    Dim num As Integer = DataSet1.Tables(0).Rows.Count - 1
    Dim no As String = "No"
    For n = num To 0 Step -1
         DataSet1.Tables(0).Rows(n).Item(2) = no
     Next
    It wasnt until i tried this on a datatable with 40k+ row that i realized how slow it was!
    It slows to a crawl and does only 2 loops or so a second (i have a i7 @ 4500Mhz)

    Hopefully you're not going to say dont use a datatable as the whole program is built around that datatable and id hate to start again over this final stumbling block for me!!

    by the way I tried it like this originally as well...
    Code:
    For Each dr As DataRow In DataSet1.Tables(0).Rows
         dr("Tested") = "No"
    Next
    hope someone can help




  2. #2
    jazzc's Avatar
    jazzc is offline Programming & Web Design Moderator black hat forumsblack hat forumsblack hat forums
    Join Date
    Jan 2009
    Posts
    2,184
    Thanks
    6,090
    Thanked 7,042 Times in 2,496 Posts

    Default Re: Why is this code so slow?

    Edit: Sorry, misread your post.

    Edit2: See this: http://msdn.microsoft.com/en-us/libr...beginedit.aspx
    Last edited by jazzc; 01-28-2013 at 07:22 PM.

  3. The Following User Says Thank You to jazzc For This Useful Post:

    tb303 (01-28-2013)

  4. #3
    tb303's Avatar
    tb303 is offline Regular Member
    Join Date
    Dec 2011
    Posts
    443
    Thanks
    199
    Thanked 119 Times in 83 Posts

    Default Re: Why is this code so slow?

    perfect. i hoped i was missing something simple.

    thanks, you've taught me something very useful there

  5. The Following User Says Thank You to tb303 For This Useful Post:

    jazzc (01-28-2013)


Similar Threads

  1. Replies: 8
    Last Post: 07-22-2012, 11:37 AM
  2. Replies: 10
    Last Post: 01-13-2011, 04:49 PM
  3. Flux rss big work and slow slow results ?
    By evamenders in forum Black Hat SEO
    Replies: 0
    Last Post: 12-17-2008, 06:57 PM
  4. slow slow to pormote aiaiaiaia
    By blannyjeanna in forum Black Hat SEO
    Replies: 12
    Last Post: 04-07-2008, 03:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




BlackHatWorld on Twitter BlackHatWorld on FaceBook


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109