Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. .net performance test. Can you guess which method is the most efficient?

.net performance test. Can you guess which method is the most efficient?

Scheduled Pinned Locked Moved The Lounge
csharpasp-netbusinessperformancequestion
32 Posts 18 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ToddHileHoffer
    wrote on last edited by
    #1

    I know there are many ways to add data to a dropdownlist in asp.net. So I thought I would use JetBrains dotTrace to see if it is more efficient to call a controls DataBind() method or add new listItems with your own code. The results were a bit surprising. I will post them later tonight after you all have chance to guess. Which method do you think will be the most efficient and why? public void initList(DataTable dt) { DropDownList1.DataSource = dt; DropDownList1.DataTextField = "empName"; DropDownList1.DataValueField = "empNumber"; DropDownList1.DataBind(); } public void initList2(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList2.Items.Add(new ListItem(r["empName"].ToString(), r["empNumber"].ToString())); } } public void initList3(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList3.Items.Add(new ListItem(r[0].ToString(), r[1].ToString())); } }

    I didn't get any requirements for the signature

    C T P A C 5 Replies Last reply
    0
    • T ToddHileHoffer

      I know there are many ways to add data to a dropdownlist in asp.net. So I thought I would use JetBrains dotTrace to see if it is more efficient to call a controls DataBind() method or add new listItems with your own code. The results were a bit surprising. I will post them later tonight after you all have chance to guess. Which method do you think will be the most efficient and why? public void initList(DataTable dt) { DropDownList1.DataSource = dt; DropDownList1.DataTextField = "empName"; DropDownList1.DataValueField = "empNumber"; DropDownList1.DataBind(); } public void initList2(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList2.Items.Add(new ListItem(r["empName"].ToString(), r["empNumber"].ToString())); } } public void initList3(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList3.Items.Add(new ListItem(r[0].ToString(), r[1].ToString())); } }

      I didn't get any requirements for the signature

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      ToddHileHoffer wrote:

      public void initList3(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList3.Items.Add(new ListItem(r[0].ToString(), r[1].ToString())); } }

      Because it doesn't have to map a name to an index, and because your databind is essentially going to look them up by name, assign a reference to the data table as the source, etc.

      Christian Graus Driven to the arms of OSX by Vista.

      J 1 Reply Last reply
      0
      • T ToddHileHoffer

        I know there are many ways to add data to a dropdownlist in asp.net. So I thought I would use JetBrains dotTrace to see if it is more efficient to call a controls DataBind() method or add new listItems with your own code. The results were a bit surprising. I will post them later tonight after you all have chance to guess. Which method do you think will be the most efficient and why? public void initList(DataTable dt) { DropDownList1.DataSource = dt; DropDownList1.DataTextField = "empName"; DropDownList1.DataValueField = "empNumber"; DropDownList1.DataBind(); } public void initList2(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList2.Items.Add(new ListItem(r["empName"].ToString(), r["empNumber"].ToString())); } } public void initList3(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList3.Items.Add(new ListItem(r[0].ToString(), r[1].ToString())); } }

        I didn't get any requirements for the signature

        T Offline
        T Offline
        ToddHileHoffer
        wrote on last edited by
        #3

        http://farm4.static.flickr.com/3024/3101270498_dc5b5bfb95_o.png[^] Amazing that initList is 10X slower than doing it manually. It really makes me wonder... I was also surprised that initList2 and initList3 took exactly the same amount of time.

        I didn't get any requirements for the signature

        U L C E 4 Replies Last reply
        0
        • T ToddHileHoffer

          http://farm4.static.flickr.com/3024/3101270498_dc5b5bfb95_o.png[^] Amazing that initList is 10X slower than doing it manually. It really makes me wonder... I was also surprised that initList2 and initList3 took exactly the same amount of time.

          I didn't get any requirements for the signature

          U Offline
          U Offline
          User of Users Group
          wrote on last edited by
          #4

          You ain't seen nothing, it slows down by 2 to 5 orders of magnitude for dynamic, updating scenarios.. that is across techs: web, desktop, browser.. MS never ever did data-binding right apart from those basic, static, form apps, occasional dynamic update, but nothing scalable, you know: IT Programming Kind. (add some XML to make it faster :laugh: )

          A A 2 Replies Last reply
          0
          • T ToddHileHoffer

            I know there are many ways to add data to a dropdownlist in asp.net. So I thought I would use JetBrains dotTrace to see if it is more efficient to call a controls DataBind() method or add new listItems with your own code. The results were a bit surprising. I will post them later tonight after you all have chance to guess. Which method do you think will be the most efficient and why? public void initList(DataTable dt) { DropDownList1.DataSource = dt; DropDownList1.DataTextField = "empName"; DropDownList1.DataValueField = "empNumber"; DropDownList1.DataBind(); } public void initList2(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList2.Items.Add(new ListItem(r["empName"].ToString(), r["empNumber"].ToString())); } } public void initList3(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList3.Items.Add(new ListItem(r[0].ToString(), r[1].ToString())); } }

            I didn't get any requirements for the signature

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I never use DataBind... never have, never will.

            C H J 3 Replies Last reply
            0
            • T ToddHileHoffer

              http://farm4.static.flickr.com/3024/3101270498_dc5b5bfb95_o.png[^] Amazing that initList is 10X slower than doing it manually. It really makes me wonder... I was also surprised that initList2 and initList3 took exactly the same amount of time.

              I didn't get any requirements for the signature

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Isn't this one of those times, though, that a) you rarely have 1000 items in a dropdown and b) the real time taken (from the user's perspective) doesn't usually affect the app significantly enough to bother. I confess to rarely using databinding - more because I am from the old school of liking to control what I am doing than for any performance considerations Where drop downs have a handful of items - especially where it's a simple case of selecting the ID for something from a list of options, it's far more easy to just bind 'em and to hell with the extra 37 milliseconds. (In the real world, I have my own controls for doing this, and they don't use binding, ut again, not because of performance issues.

              If I knew then what I know today, then I'd know the same now as I did then - then what would be the point? .\\axxx (That's an 'M')

              T 1 Reply Last reply
              0
              • P PIEBALDconsult

                I never use DataBind... never have, never will.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                I use it all the time. I always maintain that writing code that is machine readable is easy, and if I lose a bit of performance, but the end user doesn't ever notice, b/c there's 10 items in the list, then it's more important to write easily human readable code.

                Christian Graus Driven to the arms of OSX by Vista.

                P J 2 Replies Last reply
                0
                • T ToddHileHoffer

                  http://farm4.static.flickr.com/3024/3101270498_dc5b5bfb95_o.png[^] Amazing that initList is 10X slower than doing it manually. It really makes me wonder... I was also surprised that initList2 and initList3 took exactly the same amount of time.

                  I didn't get any requirements for the signature

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  ToddHileHoffer wrote:

                  I was also surprised that initList2 and initList3 took exactly the same amount of time.

                  I'm not, I'd have expected the column indexes to column names to be cached on load of the data, not looked up every time. I just made my guess based on a worst case scenario :-)

                  Christian Graus Driven to the arms of OSX by Vista.

                  1 Reply Last reply
                  0
                  • C Christian Graus

                    I use it all the time. I always maintain that writing code that is machine readable is easy, and if I lose a bit of performance, but the end user doesn't ever notice, b/c there's 10 items in the list, then it's more important to write easily human readable code.

                    Christian Graus Driven to the arms of OSX by Vista.

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    And what part of "DataBind" is easily human readable? :-D

                    C 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      And what part of "DataBind" is easily human readable? :-D

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #10

                      Coming from ASP.NET, I guess, I find it very readable, it's certainly a well defined paradigm in .NET.

                      Christian Graus Driven to the arms of OSX by Vista.

                      U 1 Reply Last reply
                      0
                      • U User of Users Group

                        You ain't seen nothing, it slows down by 2 to 5 orders of magnitude for dynamic, updating scenarios.. that is across techs: web, desktop, browser.. MS never ever did data-binding right apart from those basic, static, form apps, occasional dynamic update, but nothing scalable, you know: IT Programming Kind. (add some XML to make it faster :laugh: )

                        A Offline
                        A Offline
                        Anton Afanasyev
                        wrote on last edited by
                        #11

                        So true. At my previous-previous job, I kinda did my version of databinding, which turned out to be at least twice as fast as MS' implementation. Funny thing, I didnt understand databinding that well to begin with, which made me do my own implementation, which turned out to be faster. And then a new dude joined, and I was being heavily criticized for rolling my own. Good thing it would take too long to change to databinding. heh.

                        :badger:

                        F 1 Reply Last reply
                        0
                        • C Christian Graus

                          I use it all the time. I always maintain that writing code that is machine readable is easy, and if I lose a bit of performance, but the end user doesn't ever notice, b/c there's 10 items in the list, then it's more important to write easily human readable code.

                          Christian Graus Driven to the arms of OSX by Vista.

                          J Offline
                          J Offline
                          Judah Gabriel Himango
                          wrote on last edited by
                          #12

                          We'd love to use 100% databinding, but WinForms databinding is very limited compared to WPF. So we databinding where we can, and manual data display/updating where we can't. The heavyweight argument for databinding is this: you write less code. Less code means fewer bugs.

                          Tech, life, family, faith: Give me a visit. The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                          C 1 Reply Last reply
                          0
                          • C Christian Graus

                            Coming from ASP.NET, I guess, I find it very readable, it's certainly a well defined paradigm in .NET.

                            Christian Graus Driven to the arms of OSX by Vista.

                            U Offline
                            U Offline
                            User of Users Group
                            wrote on last edited by
                            #13

                            The clear cut problem is that they packaged it up as generic. And a good proportion of apps will simply fall apart in already dreadful slow JITing, fast memory busting and snale-pace loading environment. And binding to controls, doing things manually, with generics, your api and 'library' (foreign concept in CLR having its own idiom of everything is a framework) ends up a huge improvement on UI experience. As reusable as DataSource property. But I agree it can make sense, just that they simply refuse to adress the problem, it isn't a generic solution, dependency properties aren't either. Policy based design is, and then you chose the lot, threading, style, you name it. Bad design job, and driven by C# language shortcomings in meta-programming first and foremost, yet they keep asking for more framework design guidelines that simply aren't even close to solid engineering at all. All about being pretty... dynamic query is about the only good benefit you get, but be prepared to embrace the DataSet suicide mission.

                            modified on Thursday, December 11, 2008 7:19 PM

                            1 Reply Last reply
                            0
                            • J Judah Gabriel Himango

                              We'd love to use 100% databinding, but WinForms databinding is very limited compared to WPF. So we databinding where we can, and manual data display/updating where we can't. The heavyweight argument for databinding is this: you write less code. Less code means fewer bugs.

                              Tech, life, family, faith: Give me a visit. The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                              C Offline
                              C Offline
                              Christian Graus
                              wrote on last edited by
                              #14

                              Yes, I agree. Slow or not, I can assume that databinding works. One line to debug instead of 10 is a powerful arguement. Our iPhone app, I wrote my own scrolling/zooming code, and abandoned it for generic code that worked no better, simply because going from 200 lines of code to two, meant a lot less work when it came to tracking down bugs.

                              Christian Graus Driven to the arms of OSX by Vista.

                              K 1 Reply Last reply
                              0
                              • P PIEBALDconsult

                                I never use DataBind... never have, never will.

                                H Offline
                                H Offline
                                Henry Minute
                                wrote on last edited by
                                #15

                                I'm with Christian on this one, in that I use DataBind... whenever I can, or at least whenever it makes sense to me to do so. Howver I don't write apps for public consumption, only for my own use/enjoyment and therefore rarely have truly large amounts of data to handle. Nonetheless those apps that I do write seem to run at a reasonable speed.

                                Henry Minute Never read Medical books. You could die of a misprint. - Mark Twain

                                1 Reply Last reply
                                0
                                • T ToddHileHoffer

                                  http://farm4.static.flickr.com/3024/3101270498_dc5b5bfb95_o.png[^] Amazing that initList is 10X slower than doing it manually. It really makes me wonder... I was also surprised that initList2 and initList3 took exactly the same amount of time.

                                  I didn't get any requirements for the signature

                                  E Offline
                                  E Offline
                                  Ennis Ray Lynch Jr
                                  wrote on last edited by
                                  #16

                                  I hate using databinding. Considering the code to populate manually is the same as the code to bind I always bind. Databinding is so limited and causes more problems than it is worth.

                                  Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
                                  Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
                                  Most of this sig is for Google, not ego.

                                  T 1 Reply Last reply
                                  0
                                  • C Christian Graus

                                    Yes, I agree. Slow or not, I can assume that databinding works. One line to debug instead of 10 is a powerful arguement. Our iPhone app, I wrote my own scrolling/zooming code, and abandoned it for generic code that worked no better, simply because going from 200 lines of code to two, meant a lot less work when it came to tracking down bugs.

                                    Christian Graus Driven to the arms of OSX by Vista.

                                    K Offline
                                    K Offline
                                    KungFuCoder
                                    wrote on last edited by
                                    #17

                                    I'd back this up I'd say I find databinding faster where it matters most i.e. getting a demo out to the client so they can confirm it's what they actually wanted. I tend to go for 1. Get something to the client so I know I'm not wasting my time developing something they aren't going to be happy with. 2. Sort out performance issues if (and only if) needed. Databind is faster to set up leaving more time in the budget for everything else. I'll change it if I need to but ultimately (from a business point of view) the only 2 things that matter are is the client happy and is it in budget. Personally I'll always go for the fast and elegant solution if I have a choice but that's often slower to write and not exactly what I get paid for.

                                    1 Reply Last reply
                                    0
                                    • A Anton Afanasyev

                                      So true. At my previous-previous job, I kinda did my version of databinding, which turned out to be at least twice as fast as MS' implementation. Funny thing, I didnt understand databinding that well to begin with, which made me do my own implementation, which turned out to be faster. And then a new dude joined, and I was being heavily criticized for rolling my own. Good thing it would take too long to change to databinding. heh.

                                      :badger:

                                      F Offline
                                      F Offline
                                      Fabio Franco
                                      wrote on last edited by
                                      #18

                                      I've always done the DataBinding manually as it gives me more control on handling data and it is more fun. Now I just have another good reason keep doing it my way.

                                      1 Reply Last reply
                                      0
                                      • U User of Users Group

                                        You ain't seen nothing, it slows down by 2 to 5 orders of magnitude for dynamic, updating scenarios.. that is across techs: web, desktop, browser.. MS never ever did data-binding right apart from those basic, static, form apps, occasional dynamic update, but nothing scalable, you know: IT Programming Kind. (add some XML to make it faster :laugh: )

                                        A Offline
                                        A Offline
                                        Alister Cole
                                        wrote on last edited by
                                        #19

                                        Try and set the datasource after you set the DisplayMember and Value Member and you will find that the time taken to bind is reduced significantly. My case (with approx 600 rows in a C# WINDOWS app): datasource set before DisplayMember and Value Member = 106 ms datasource set after DisplayMember and Value Member = 36 ms When I tried to manually bind, I got a result of 106 ms.

                                        1 Reply Last reply
                                        0
                                        • T ToddHileHoffer

                                          I know there are many ways to add data to a dropdownlist in asp.net. So I thought I would use JetBrains dotTrace to see if it is more efficient to call a controls DataBind() method or add new listItems with your own code. The results were a bit surprising. I will post them later tonight after you all have chance to guess. Which method do you think will be the most efficient and why? public void initList(DataTable dt) { DropDownList1.DataSource = dt; DropDownList1.DataTextField = "empName"; DropDownList1.DataValueField = "empNumber"; DropDownList1.DataBind(); } public void initList2(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList2.Items.Add(new ListItem(r["empName"].ToString(), r["empNumber"].ToString())); } } public void initList3(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList3.Items.Add(new ListItem(r[0].ToString(), r[1].ToString())); } }

                                          I didn't get any requirements for the signature

                                          A Offline
                                          A Offline
                                          Adriaan Davel
                                          wrote on last edited by
                                          #20

                                          I'm not a technical guru, and often I have heard people argue about best performance and the difference being milliseconds (like in this case), yet they will "forget" to index a SQL table, or write bad SQL queries etc. I hardly ever bother with performance in the UI layer as data driven applications your data IO is your crucial hit point. Reading 1000 rows badly compared to reading it well from a SQL table will have far bigger impact than adding the results to a list in different ways. I suppose if you are already doing high performance data IO then UI performace can get important, but who has the luxury of time for low results tweaking :-D

                                          ____________________________________________________________ Be brave little warrior, be VERY brave

                                          J T 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups