Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Programming

Ask Slashdot: What's the Most Often-Run Piece of Code -- Ever? 533

Hugo Villeneuve writes "What piece of code, in a non-assembler format, has been run the most often, ever, on this planet? By 'most often,' I mean the highest number of executions, regardless of CPU type. For the code in question, let's set a lower limit of 3 consecutive lines. For example, is it:
  • A UNIX kernel context switch?
  • A SHA2 algorithm for Bitcoin mining on an ASIC?
  • A scientific calculation running on a supercomputer?
  • A 'for-loop' inside on an obscure microcontroller that runs on all GE appliance since the '60s?"
This discussion has been archived. No new comments can be posted.

Ask Slashdot: What's the Most Often-Run Piece of Code -- Ever?

Comments Filter:
  • by Murdoch5 ( 1563847 ) on Saturday January 18, 2014 @06:58PM (#46001141) Homepage
    for(;;){
    }

    OR

    while(1){
    }

    Starts all main control loops and all kernels.
    • by kav2k ( 1545689 )

      Fails the 3-line minimum.

    • int main(int argc, char **argv) {
      ...
      return 0;
      }
      • Maybe but most control systems wouldn't make main return int. Best practice in embedded programming is to make main return void, because you use a custom linker.
        • That actually breaks the C standard, but I suppose control systems aren't much worried about portability.

          • Well the theory is that in a control system main is the only entry to the entire system, so you never have to go anywhere else and hence never return form the entry, so main can be void.
          • Re:For / While in C (Score:5, Informative)

            by Dahan ( 130247 ) <khym@azeotrope.org> on Saturday January 18, 2014 @07:42PM (#46001533)

            That actually breaks the C standard, but I suppose control systems aren't much worried about portability.

            The ANSI C standard defines two types of implementations: "hosted" and "freestanding". An embedded system would most likely be considered a freestanding implementation, in which case, the entry point function can be whatever the implementation defines it to be. It might not even be named "main" (but if it is, it could return void if that's what the implementation says). That said, C99 allows main() to return void, even in a hosted implementation: 5.1.2.2.1 [coding-guidelines.com] gives "some other implementation-defined manner." as one of the options for main's definition. It notes in 5.1.2.2.3 [coding-guidelines.com] that "If the return type is not compatible with int, the termination status returned to the host environment is unspecified."

      • TFA: "let's set a lower limit of 3 consecutive lines."

    • by Anonymous Coward on Saturday January 18, 2014 @07:23PM (#46001399)

      Perhaps a pixel shader in a modern video game on console or PC, executed per pixel at HD resolution, and for hours (average play time) on tens of millions of machines?

      Could be approaching 10^20 executions.

      • Re: (Score:3, Interesting)

        by SydShamino ( 547793 )

        Lines of code I've written in HDL execute in hardware once every clock cycle, at, say 100 MHz on maybe 50,000 devices for at least a few years of active use each. That's like 3x10^20 executions alone, and I work for a specialty hardware company which has only sold ~50,000 devices I've designed over the past 13+ years. I'm quite certain other hardware developers have far, far more, and the original question doesn't necessarily seem to require code that executes in a processor versus inferring hardware.

        (And

  • Obligatory (Score:5, Insightful)

    by fisted ( 2295862 ) on Saturday January 18, 2014 @06:58PM (#46001143)

    Every Ask Slashdot gets a comment pointing out that it's the dumbest Ask Slashdot ever, I know.

    This time, it's really, really the case.

    • Re:Obligatory (Score:5, Insightful)

      by Workaphobia ( 931620 ) on Saturday January 18, 2014 @07:13PM (#46001289) Journal

      I disagree. This may be the superlative of something, but I don't think "dumb" is it.

      I actually think it's an interesting thought experiment. It immediately forces the reader to think about how pieces of code are used in the real world, both within and beyond their intended application. But it is also likely impossible to settle to anyone's satisfaction. I would trust a proposed answer to this question even less than I would an answer to "What was the size of the internet at the time of the Morris worm", or "How many lines of C code are there in existence".

      Just because something's hard to measure doesn't make it dumb, though.

    • Re:Obligatory (Score:4, Interesting)

      by foobar bazbot ( 3352433 ) on Saturday January 18, 2014 @07:22PM (#46001387)

      I know this is OT, but

      Every Ask Slashdot gets a comment pointing out that it's the dumbest Ask Slashdot ever, I know.

      This time, it's really, really the case.

      True. But more importantly: I never knew /. let us do nested bold levels!

      For anyone too lazy to look at the html source...

      I never knew /. let us do <b>nested <b>bold</b> levels!</b>

    • Re:Obligatory (Score:5, Insightful)

      by d33tah ( 2722297 ) on Saturday January 18, 2014 @07:55PM (#46001637)
      Personally I think that the biggest problem with Slashdot is the abundance of comments like this. Seriously, it might not meet your standards. I understand. Now get over it and stop wasting my time writing it for the thousandth time or actually submit an article that raises the bar. Whining is not really going to change anything. Sorry, but I really had to.
      • by dissy ( 172727 )

        What's even more hilarious, people like the GP who claim to hate a type of article then proceed to post in each and every one of them are in reality raising two counters in a database somewhere when they #1 click on the article and #2 post a comment.
        This indicates to slashdot that the article was both interesting to read as well as interesting enough to have participation, and the interpreted result is the readers want MORE articles of that nature!

        So when people say "complaining is the only way to get chang

    • by RedBear ( 207369 )

      Every Ask Slashdot gets a comment pointing out that it's the dumbest Ask Slashdot ever, I know.

      This time, it's really, really the case.

      On the contrary. Unless you have a definitive and provably correct answer to this particular Ask Slashdot, which I didn't notice you providing, I would assert that it's an interesting question and you're just being a jackass.

  • by multimediavt ( 965608 ) on Saturday January 18, 2014 @06:58PM (#46001145)
    I would have to guess some code in BIOS that's pretty much the same on every platform. The POST components for memory checking, for instance. That might actually get disqualified as they may be written in assembler?
    • No. BIOS code only gets run at boot time.

      • Re:Bios code? (Score:5, Interesting)

        by Anonymous Coward on Saturday January 18, 2014 @07:05PM (#46001201)

        I would probably have to say whatever is the inner loop on the system idle process in windows.

        • Re:Bios code? (Score:5, Informative)

          by Orp ( 6583 ) on Saturday January 18, 2014 @07:36PM (#46001499) Homepage

          I would probably have to say whatever is the inner loop on the system idle process in windows.

          Ding, we have a winner. Not supercomputer code. Sure, supercomputers are... super and all, but the biggest one only has around 1 million processing cores. How many windoze machines are out there, idling away?

        • Re:Bios code? (Score:5, Insightful)

          by mhotchin ( 791085 ) <<slashdot> <at> <hotchin.net>> on Saturday January 18, 2014 @08:42PM (#46001899)

          Actually, it's likely not executed that many times - the CPU goes into HALT when idle, and wakes up when there's work to do. Gone are the days of endlessly spinning....

          The Idle Process may be more book-keeping artifact than actual code.

      • Re: (Score:2, Insightful)

        by ColdWetDog ( 752185 )

        Well, all of those Windows reboots ought to bump the value up a fair bit.

      • Re:Bios code? (Score:5, Insightful)

        by buchner.johannes ( 1139593 ) on Saturday January 18, 2014 @07:33PM (#46001467) Homepage Journal

        Lets approach this analytically.

        What platform has the most computation power (number of CPUs x speed)?
        Due to the increase in speed, we can disregard any CPUs built before 2000.

        In number, mobile phones are the largest platform. So I would reckon, some GSM codec/cipher.

        I think, for now, microcontrollers can be ignored, because they have much lower computational power.

        Desktops and supercomputers have more power, but are they excessing the mobile phones? If they are a relevant portion, then across mobile phones and desktops, perhaps some code related to network access is the most-run.

        I doubt it would be something kernel-related (like bootup, context-switching), because the kernel usually does not (or should not) take up a lot of the computing time. If we go by number of entries only, then perhaps some networking code.

        If so, I'm not sure which layer to look into though. The lower ones are called more often, but media is not the same across use cases.

        • Come on.... ( pun intended )

          It almost has to be a video / image codec if we are talking about internet era code. I mean the internet is what, 90% porn?

          But in all seriousness, I would still say video codec code. All the devices out there consuming video at (usually) 24+FPS have to decode each frame. The line kind of blurs with DXVA / VDPAU and hardware decoding though.

          Come to think of it, it could also easily be an audio codec, either in portable music players or cell phones.

        • by AmiMoJo ( 196126 ) *

          So I would reckon, some GSM codec/cipher.

          That is usually done by an ASIC though, so not code per-se. Parts of the radio in mobile phones are programmable, although they tend to be FPGAs rather than CPUs at the core because that reduces power when doing DSP type stuff. I'm not sure if FPGA code counts because it's not really executed like CPU code is.

          There are a lot of similar candidates that fall into this trap. Hashing code, encryption code, checksumming code... Whenever it needs to be high performance it's usually better to create a hardware imp

    • Re:Bios code? (Score:5, Interesting)

      by Rockoon ( 1252108 ) on Saturday January 18, 2014 @07:54PM (#46001631)
      You are right about the hardware/bios aspect, but arent on the right device.

      (nearly) Every computer has a video device which has a loop running over the frame buffer, outputting pixels to the display output port. Even in the days of regular CGA 320x200 graphics on 60hz monitors that amounted to 3,840,000 iterations per second. We are talking over 3 decades of this going on, on nearly every desktop and laptop computer build during that time (vector displays worked differently) and even in those early days of CGA most of the time those machines were in a text mode with a pixel resolution of 720x240 and still putting out a 60hz of video signal (10,368,000 pixels per second.)

      A single CGA desktop machine in text mode left on since January 1984 would have output 9,816,000,000,000,000 pixels to its display port so far. Thats nearly 10 quadrillion pixels. Even if the average number of running desktop computers over the period were only 1 million (a severe lowball) and used that shitty low resolution at only 60 hz, thats still over a sextillion iterations of that simple pixel outputting loop.

      I would say the average number of running desktops over the period since 1984 is more like 50 million and the average resolution over the period was 1024x768, and the average monitor refresh is 70 hz. My guestimate is about 2.606E+24 iterations of the framebuffer loop, over 2 septillion iterations.
      • by 0123456 ( 636235 )

        (nearly) Every computer has a video device which has a loop running over the frame buffer, outputting pixels to the display output port.

        Unless you're using a Sinclair ZX80/81 or some other peculiar device that's too cheap to include a graphics chip, that's hardware, not 'code'. If you expand the definition of 'code' to VHDL and other hardware design languages, there must be 'code' doing far more than a graphics chip would.

    • by Memnos ( 937795 ) on Sunday January 19, 2014 @01:59AM (#46003385) Journal
      I would have to guess any error handling code I have ever written. It may not be the most oft-run code, but for me it sure seems like it is..
  • by SYSS Mouse ( 694626 ) on Saturday January 18, 2014 @06:59PM (#46001147) Homepage

    Indeed.

  • by psergiu ( 67614 ) on Saturday January 18, 2014 @07:00PM (#46001161)

    Must be the SlashCode "asciifier" which removes all non-ASCII characters in summaries and posts, thus mangling a lot of names, locations and math formulas.

  • Solved. Next? (Score:5, Insightful)

    by Anonymous Coward on Saturday January 18, 2014 @07:01PM (#46001171)

    Question: What piece of code, in a non-assembler format, has been run the most often, ever, on this planet? By 'most often,' I mean the highest number of executions, regardless of CPU type.

    Answer: Genetic code.

    • Insightful? Come off it. It's a pun.

  • by Nutria ( 679911 ) on Saturday January 18, 2014 @07:02PM (#46001183)

    of the Windows NT kernel that hasn't changed since the 1990s?

    • ...of the Windows NT kernel that hasn't changed since the 1990s?

      Because we know there's nothing like that in the Linux kernel...

      • Superintendent Chalmers: A graphics system... in the linux kernel... and hasn't changed... since the '90s?
        Principal Skinner: Yes!
        Superintendent Chalmers: May I see it?
        Principal Skinner: Er, no.

  • by dpbsmith ( 263124 ) on Saturday January 18, 2014 @07:03PM (#46001187) Homepage

    How could this ever be more than a guess? How could it ever be determined, documented, or verified?

    And for that matter, what is the definition of whether something is "the same" piece of code? For example, if the same source code compiles to different instructions on two platforms, are they running the same code?

    How about if one of them actually compiles code that gets executed, and the other optimizes it out?

  • by Anonymous Coward on Saturday January 18, 2014 @07:08PM (#46001231)

    http://en.wikipedia.org/wiki/IEFBR14

    Any time a mainframe does anything with a dataset in a batch job (i.e. allocate, delete, whatever) it runs IEFBR14, a null program, as a target program to satisfy a requirement in how jobs are created.

    This means that banks, retailers, governments, you name it--when they process the back-end records that make modern life functional, IEFBR14 usually gets invoked somewhere.

  • printf("Hello, World!\n");
    • by Zumbs ( 1241138 )
      I suspect that the "Hello, World" program is the most commonly *printed* (on paper, in books) piece of code, ever.
  • My guess would be the code in 'System Idle Process'.

  • by AuMatar ( 183847 ) on Saturday January 18, 2014 @07:12PM (#46001273)

    for(int i=0; iSOME_LENGTH; i++){
          array[i] = 0;
    }

    Run 100s of times per program, for almost all programs

  • by stox ( 131684 ) on Saturday January 18, 2014 @07:15PM (#46001309) Homepage

    eg. Call timer code in the 5ESS switch. Countless millions of times a day for over 30 years now. Probably the oldest code that we all depend on every day.

  • ob (Score:5, Funny)

    by Hognoxious ( 631665 ) on Saturday January 18, 2014 @07:15PM (#46001311) Homepage Journal

    on anything {
        displayHWinPtrAddrPtrScreen( {492EC5F8-477F-438E}.color.const::BLUE status:{492EC5F8-477F-438E}.const.DEATH } )
    }

  • by Anonymous Coward

    The keyboard scan loop in Windows gets my vote.

  • As most of us know, and the rest of us ought to, x86 and many other CISC architectures have their instruction set decoupled from the internal microarchitecture by using microcode [wikipedia.org].

    Since multiple microcode instructions can run for one machine instruction, there's likely a sequence of three or more instructions used by many common instructions (I'm guessing something pertaining to checking for cache misses?) that thus gets executed more often than any single opcode on that machine.

    • Gah! I missed the "in a non-assembler format" qualifier. I'm not sure what exactly that means, but I suppose it was intended to rule out smart-ass answers like mine.

  • i=i+1 or i+=1 or i++

    • For the code in question, let's set a lower limit of 3 consecutive lines.

      You have failed to adhere to the asker's arbitrary criteria! Goodnight!

  • ...and all you ever saw on store displays in the 80's was the result of:

    10 PRINT "FUCK "
    20 GOTO 10

    I'd have to say that code is a contender.

  • I'm fairly certain that all the BSD's including OS X use a standardized login.c Though my money would be on there being some system related windows code that has been the same since the 90s.

  • Browser code for reloading a page... mostly on Slashdot. No, really, how about an inner loop of a Windows screensaver?
  • int main (argc, argv)
    char **argv;
    {

  • I read this as a multiple choice question with a defined answer. I was disappointed when I figured it out, because I was hoping I had correctly picked D. Sigh.
  • Most OSes have some code that runs when other processes aren't running to measure the idle time. Certainly in Windows, this is a process in it's own right.
    If the CPU is only 1% utilised, then the idle time process is consuming most of the remaining 99% (with the kernel using a bit of that).

    So, I would hazard a guess that it's something in this.

    (Or, for Windows, the code that swaps pages out to disk.)

    • by dak664 ( 1992350 )

      On modern operating systems the idle loop is never coded in a high level language. It is painstakingly optimized in assembly language, for maximum speed.

  • i++

    or

    MOV EAX, [EBX]

    or

    INC EAX

  • Man file has run and still continues to run on more computers than ever before and frankly refuses to die. It won't ever go away.

  • For an all-time high, you want a combination of a large number of devices, over a long period of time.

    I'd say cell phones would do nicely. Probably something that runs often on all cells everywhere. Maybe something that sync's with cell towers, or handles jumping between towers.

    Maybe text message handling code. How many texts are sent per day?

  • Comment removed based on user account deletion
  • Ignoring the '3 line' thing because that's just dumb, my vote for the most run piece of code on the planet right now would be:

    DNS. Either the part that queries or the part that answers.

    Think about how many times that's being called at this moment, globally.

    (And yes, this Ask /. is the stupidest ever.)

  • The routine used in calculating Pi.

              int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;
              for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,
              f[b]=d%--g,d/=g--,--b;d*=b);}

  • ....are more of an early-70s thing. The 60s was all about integrated hand-engineered hard-wired logic, & even then it's a late-60s thing.
  • The code for sleep() should be the most executed code.
  • For a GIF of less than two million pixels, say 1600x1200, and each pixel's colour selected from a palette of 256 colours and dependent on neighbouring pixels' colour values derived from the same iterative algorithm run 1 million times to maximise value stability per pixel, you're looking at running the same line of code 4.9152*10^14 times.

    Assuming 100% (as in perfect) saturation on a 2GHz processor core, that'll take just over 68 hours.Or, to use the old industry yardstick, 63.2 P90-days.

    (source: mad guy wi

  • Based on the number of graphics cards out there, the high repetitive nature of their application and the fact that that's all they do, it's probably something related to them. I thought of supercomputers running very small recursive routines, but they usually have a limited lifetime and older computers aren't fast enough and haven't continued to run in any event.

    Graphics though? I'd guess something in a very common graphics card would probably be in the scale to achieve the title of most-run code.

    Though if

  • Scrypt (Score:3, Interesting)

    by mysidia ( 191772 ) on Saturday January 18, 2014 @07:55PM (#46001643)
    static inline void B(void *blah, uint32_t a)
    {
    uint8_t * z = (uint8_t *)blah;
    z[0] = (a >> 24) & 0xff;
    z[1] = (a >> 16) & 0xff;
    z[2] = (a >> 8) & 0xff;
    z[3] = a & 0xff;

    }
  • by msobkow ( 48369 ) on Saturday January 18, 2014 @08:35PM (#46001865) Homepage Journal

    The counters in digital clocks have furiously been counting clock ticks to the next second since the '70s, if not earlier.

I have hardly ever known a mathematician who was capable of reasoning. -- Plato

Working...