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. Other Discussions
  3. The Weird and The Wonderful
  4. A new definition of efficiency

A new definition of efficiency

Scheduled Pinned Locked Moved The Weird and The Wonderful
questionlearning
11 Posts 9 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.
  • P PaulLinton

    Just saw this posted on another forum

    List _chars = new List();

    for (int i = 0; i < 2000; i++)
    {
    if ((i >= 48 && i <= 57) || (i >= 97 && i <= 122))
    {
    _chars.Add((char)i);
    }
    }

    The author claimed that the code "work efficiently". I wonder how the upper limit of 2000 was determined? Why not int.MaxValue? Then you could maximise the inefficiency. Of course, you could do better with a long, or a lower bound of int.MinValue but that's getting silly. The way _chars was used later all that was required was

    string _chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    enhzflepE Offline
    enhzflepE Offline
    enhzflep
    wrote on last edited by
    #2

    :) :laugh: Reminds me of the old classic QA response "My code is correct, but it's not working"

    1 Reply Last reply
    0
    • P PaulLinton

      Just saw this posted on another forum

      List _chars = new List();

      for (int i = 0; i < 2000; i++)
      {
      if ((i >= 48 && i <= 57) || (i >= 97 && i <= 122))
      {
      _chars.Add((char)i);
      }
      }

      The author claimed that the code "work efficiently". I wonder how the upper limit of 2000 was determined? Why not int.MaxValue? Then you could maximise the inefficiency. Of course, you could do better with a long, or a lower bound of int.MinValue but that's getting silly. The way _chars was used later all that was required was

      string _chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #3

      Char.IsLetterOrDigit might have been a good starting point. Could have wasted hours of the authors time testing to see which was the more efficient :) Interested though if it was also a bug, 97 to 122 are all lowercase, not uppercase.

      "You get that on the big jobs."

      1 Reply Last reply
      0
      • P PaulLinton

        Just saw this posted on another forum

        List _chars = new List();

        for (int i = 0; i < 2000; i++)
        {
        if ((i >= 48 && i <= 57) || (i >= 97 && i <= 122))
        {
        _chars.Add((char)i);
        }
        }

        The author claimed that the code "work efficiently". I wonder how the upper limit of 2000 was determined? Why not int.MaxValue? Then you could maximise the inefficiency. Of course, you could do better with a long, or a lower bound of int.MinValue but that's getting silly. The way _chars was used later all that was required was

        string _chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #4

        Well obviously it is there "for future expansion". :-D Of the alphabet, I assume...

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        A 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Well obviously it is there "for future expansion". :-D Of the alphabet, I assume...

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          A Offline
          A Offline
          Andrew Rissing
          wrote on last edited by
          #5

          ¥ɛѦ, tĥѦτ ѡĭ└└ ɳɛvɛr ĥѦῤῤɛɳ‼

          OriginalGriffO _ 2 Replies Last reply
          0
          • A Andrew Rissing

            ¥ɛѦ, tĥѦτ ѡĭ└└ ɳɛvɛr ĥѦῤῤɛɳ‼

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #6

            I'm gonna need a bigger keyboard... :laugh:

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            A 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              I'm gonna need a bigger keyboard... :laugh:

              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

              A Offline
              A Offline
              Andrew Rissing
              wrote on last edited by
              #7

              All you need is the 'Alt' key and a 10-key pad. Alt-1... ☺

              S 1 Reply Last reply
              0
              • P PaulLinton

                Just saw this posted on another forum

                List _chars = new List();

                for (int i = 0; i < 2000; i++)
                {
                if ((i >= 48 && i <= 57) || (i >= 97 && i <= 122))
                {
                _chars.Add((char)i);
                }
                }

                The author claimed that the code "work efficiently". I wonder how the upper limit of 2000 was determined? Why not int.MaxValue? Then you could maximise the inefficiency. Of course, you could do better with a long, or a lower bound of int.MinValue but that's getting silly. The way _chars was used later all that was required was

                string _chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

                B Offline
                B Offline
                BillW33
                wrote on last edited by
                #8

                That code might work, but I would not call it efficient. :wtf:

                Just because the code works, it doesn't mean that it is good code.

                1 Reply Last reply
                0
                • A Andrew Rissing

                  ¥ɛѦ, tĥѦτ ѡĭ└└ ɳɛvɛr ĥѦῤῤɛɳ‼

                  _ Offline
                  _ Offline
                  _Amy
                  wrote on last edited by
                  #9

                  If it will not happen then select the code file press shift + delete.. .......If possible.. :laugh:

                  Read the article "Table Valued Parameters". --Amit

                  1 Reply Last reply
                  0
                  • A Andrew Rissing

                    All you need is the 'Alt' key and a 10-key pad. Alt-1... ☺

                    S Offline
                    S Offline
                    SortaCore
                    wrote on last edited by
                    #10

                    I wonder who decided that the smiley was most important key to put on Alt? I noticed they had a Alt+2 for the other coders. ☻

                    1 Reply Last reply
                    0
                    • P PaulLinton

                      Just saw this posted on another forum

                      List _chars = new List();

                      for (int i = 0; i < 2000; i++)
                      {
                      if ((i >= 48 && i <= 57) || (i >= 97 && i <= 122))
                      {
                      _chars.Add((char)i);
                      }
                      }

                      The author claimed that the code "work efficiently". I wonder how the upper limit of 2000 was determined? Why not int.MaxValue? Then you could maximise the inefficiency. Of course, you could do better with a long, or a lower bound of int.MinValue but that's getting silly. The way _chars was used later all that was required was

                      string _chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

                      E Offline
                      E Offline
                      englebart
                      wrote on last edited by
                      #11

                      I think you meant: string _chars = "0123456789abcdefghijklmnopqrstuvwxyz"; (lowercase) :) 65 = A, 97 = a Your version is definitely more readable (and efficient). Based on the default List length, it might reallocate (and copy) the memory backing the list a few times.

                      1 Reply 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