Slashdot Mirror


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

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?"

61 of 533 comments (clear)

  1. For / While in C by Murdoch5 · · Score: 5, Funny

    for(;;){
    }

    OR

    while(1){
    }

    Starts all main control loops and all kernels.

    1. Re:For / While in C by Ragzouken · · Score: 5, Funny

      for(;;)
      {
      }

      while(1)
      {
      }

    2. Re: For / While in C by Anonymous Coward · · Score: 5, Insightful

      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.

    3. Re:For / While in C by Dahan · · Score: 5, Informative

      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 gives "some other implementation-defined manner." as one of the options for main's definition. It notes in 5.1.2.2.3 that "If the return type is not compatible with int, the termination status returned to the host environment is unspecified."

    4. Re:For / While in C by ConstantineM · · Score: 2

      Which one does the Linux kernel use?

      Not sure, but OpenBSD has this at the very end of its main():

      while (1)
      tsleep(&proc0, PVM, "scheduler", 0);
      /* NOTREACHED */

      I tried finding the FreeBSD equivalent, but their (Newbus?) code makes it entirely non-obvious where the loop is. Feel free to try your luck — only the comment to what the startup function is supposed to do matches, but the rest is quite unique, even a different function name — mi_startup() on FreeBSD.

    5. Re:For / While in C by Anonymous Coward · · Score: 2, Interesting

      I wouldn't trust any C programmer who doesn't have a copy of the standard on his desktop (actual or digital).

      Unlike most standards it's concise and well organized. If you're too lazy to familiarize yourself with it, you're too lazy to write good C code.

    6. Re: For / While in C by drkim · · Score: 2, Interesting

      I don't anything about the code that runs in digital watches, but maybe the code that says:

      Is it time to trigger the alarm yet?
      Yes? Trigger the alarm
      No, check the time again.

      I just imagine with the sheer number of watches, cel phones, microwaves, DVRs, etc. out there this would be the most ubiquitous, and constantly running, bit of code.

    7. Re: For / While in C by RightwingNutjob · · Score: 2

      Code is a generous word. In most alarm clocks and wristwatches, this sort of thing is likely implemented in discrete logic gates, which I would say goes a little against the spirit of the rules.

    8. Re: For / While in C by SydShamino · · Score: 2, Interesting

      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 yes, there's one file that I've conveyed from project to project for everything I've designed. It generates a 100 ns time base - a one-clock-cycle-wide pulse every 100 ns - regardless of the clock frequency. It adds a little jitter to synchronize to the time base but makes it easier to change the clock frequency without breaking other real-time dependent timers.)

      --
      It doesn't hurt to be nice.
    9. Re:For / While in C by FatdogHaiku · · Score: 5, Funny

      Since no line "maximum" was defined I have to vote for SVCHOST running Windows update on XP....
      it keeps going and going and going...

      --
      You have the right to remain sentient. If you give up the right to remain sentient, you will be elected to public office
    10. Re: For / While in C by Zmobie · · Score: 5, Interesting

      I work with a ton of electrical/controls engineers. Yes it is still probably true, mostly because it is still even cheaper/easier to do this through ladder logic. I forget the context of what we were talking about one day, but one day while talking to one of our SENIOR (30+ years) controls engineers I was explaining some logic that if we had to implement it in C# would take probably 300 lines of code. His reply was simply, psh, I could do that in 3 rungs, don't bother.

    11. Re:For / While in C by jones_supa · · Score: 5, Informative

      Since no line "maximum" was defined I have to vote for SVCHOST running Windows update on XP....

      Just to be accurate... we are shooting the messenger if we blame the SVCHOST process here. It runs various services. The faulty code was in the Windows Update service (wuauserv).

      You can see all the respective services with the command tasklist /svc .

  2. Obligatory by fisted · · Score: 5, Insightful

    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.

    1. Re:Obligatory by Workaphobia · · Score: 5, Insightful

      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.

      --
      Evidently, the key to understanding recursion is to begin by understanding recursion. The rest is easy.
    2. Re:Obligatory by foobar+bazbot · · Score: 3, Interesting

      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>

    3. Re:Obligatory by d33tah · · Score: 5, Insightful

      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.

    4. Re:Obligatory by RedBear · · Score: 2

      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.

    5. Re:Obligatory by burisch_research · · Score: 2

      Heh:

      Ask Slashdot: What would be the best question to Ask Slashdot? :)

      --
      char*f="char*f=%c%s%c;main(){printf(f,34,f,34);}";main(){printf(f,34,f,34);}
    6. Re:Obligatory by serviscope_minor · · Score: 2

      I actually think it's an interesting thought experiment.

      I agree. But there's no way to get from that to this (I disagree with your reasoning):

      This really is the worst ask /. I've ever seen.

      Someone posted an interesting thought experiment to slashdot. That's great. The answers are interesting and come from many facets of tech/programming that I am not involved in.

      We'll never know the absolute truth even if such a thing exists but the answers are interesting and informative.

      I wish they'd asked something interesting, like "what did you have for breakfast?" at least I can answer that with some hope of knowing the answer.

      Yeah, but I simply don't care about the answer. The answer is not interesting.

      An interesting question (like TFA) is interesting even if you can't answer it.

      --
      SJW n. One who posts facts.
    7. Re:Obligatory by dissy · · Score: 2

      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 change", they are very correct in fact but incorrect about as far as you can be in outcome. Complaining in the comments will cause more such articles in the future, not less.

      As you already stated, the only way to assure less such articles is to skip the ones uninteresting to you and to post what you do want to see in the firehose to be upvoted for the front page.

      Anyone who doesn't use the firehose to down vote articles and then complains about articles on the front page are nearly as bad as people who refuse to vote then continuously bitch about who does get voted in to government ("nearly" because the outcome is magnitudes less important in daily life here on slashdot than who runs the worlds biggest countries)

  3. Bios code? by multimediavt · · Score: 2

    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?

    1. Re:Bios code? by chaoskitty · · Score: 2

      No. BIOS code only gets run at boot time.

    2. Re:Bios code? by Anonymous Coward · · Score: 5, Interesting

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

    3. Re:Bios code? by buchner.johannes · · Score: 4, Insightful

      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.

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    4. Re:Bios code? by Orp · · Score: 4, Informative

      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?

      --
      A squid eating dough in a polyethylene bag is fast and bulbous, got me?
    5. Re:Bios code? by Rockoon · · Score: 5, Interesting

      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.

      --
      "His name was James Damore."
    6. Re:Bios code? by 0123456 · · Score: 2

      (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.

    7. Re:Bios code? by mhotchin · · Score: 4, Insightful

      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.

    8. Re:Bios code? by 0123456 · · Score: 4, Informative

      That is also wrong.
      HALT for the CPU means furtherhin it will do nothing.
      Perhaps you ment a different opcode?

      Halt means it does nothing... until the next interrupt. Which will happen when there's something useful to do.

    9. Re:Bios code? by chmod+a+x+mojo · · Score: 2

      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.

      --
      To err is human; effective mayhem requires the root password!
    10. Re:Bios code? by Memnos · · Score: 3, Funny

      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..

      --
      I don't trust atoms -- they make up stuff.
    11. Re:Bios code? by AmiMoJo · · Score: 2

      Depends on the architecture. On many CPUs HALT stops it completely, never to resume until externally reset. There is usually a SLEEP op-code for what you are thinking of.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    12. Re:Bios code? by AmiMoJo · · Score: 2

      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 implementation, so it is no longer code.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    13. Re:Bios code? by fatphil · · Score: 2

      > You clearly think that there is only one *C*PU in your desktop

      Emphasis mine. There generally was only one *C*PU, but there may have been other ALU's or peripherals controllers (which includes graphics chips). Processors, yes, but not CPU's in the context of those systems. My mobile phone has at least 5 fully-functional ARM processors on it (not cores, processors), for example, but only one of those is the CPU.

      --
      Also FatPhil on SoylentNews, id 863
  4. Hello World. by SYSS+Mouse · · Score: 4, Funny

    Indeed.

  5. Slascode "asciifier" by psergiu · · Score: 5, Funny

    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.

    --
    1% APY, No fees, Online Bank https://captl1.co/2uIErYq Don't let your $$$ sit in a no-interest acct.
  6. Solved. Next? by Anonymous Coward · · Score: 5, Insightful

    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.

  7. Something in deep in a loop in the graphics system by Nutria · · Score: 2

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

    --
    "I don't know, therefore Aliens" Wafflebox1
  8. How could this ever be determined or verified? by dpbsmith · · Score: 3, Insightful

    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?

    1. Re:How could this ever be determined or verified? by TubeSteak · · Score: 4, Insightful

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

      How many piano tuners are there in Chicago?

      --
      [Fuck Beta]
      o0t!
  9. IEFBR14 - Mainframe Null Program by Anonymous Coward · · Score: 5, Interesting

    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.

    1. Re:IEFBR14 - Mainframe Null Program by sk999 · · Score: 5, Interesting

      This gets my vote. Ran it many times myself.

      As an aside, this program, (which did absolutely nothing and, in binary format, was originally only 2 bytes long) had the dubious reputation of being the shortest program with a bug. It failed to clear the register that returned the error code. Oops.

    2. Re:IEFBR14 - Mainframe Null Program by ihtoit · · Score: 3, Insightful

      that is actually... really fucking sad. So sad it made me laugh. Is that in itself sad?

      --
      Political debates have me rolling my eyes so much I think I got optical whiplash. I should sue. - Foamy The Squirrel
    3. Re: IEFBR14 - Mainframe Null Program by kenh · · Score: 3, Informative

      Error? More like bad coding - it relied on the processor clearing the return/exit status register originally, and once the 'error' was 'corrected' it doubled the size of the program (from one BR14 instruction to a load instruction and then the branch instruction).

      That code is now 50 years old.

      --
      Ken
    4. Re:IEFBR14 - Mainframe Null Program by QRDeNameland · · Score: 2

      I had an instructor years ago who said his only exception to his "there are no stupid questions" policy was when a student asked him "How do you spell IEFBR14?"

      --
      Momentarily, the need for the construction of new light will no longer exist.
  10. The old classic... by oldfogie · · Score: 2

    printf("Hello, World!\n");

  11. Initialize array to 0 by AuMatar · · Score: 3, Interesting

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

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

    --
    I still have more fans than freaks. WTF is wrong with you people?
    1. Re:Initialize array to 0 by Anonymous Coward · · Score: 2, Insightful

      for almost all programs... written by people who have never heard of memset (or appropriate initializations for std::vector, etc.).

  12. Probably some telphone code by stox · · Score: 3, Insightful

    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.

    --
    "To those who are overly cautious, everything is impossible. "
    1. Re:Probably some telphone code by rueger · · Score: 2

      And thirty years on many people in Canada are still charged extra each month for "touch-tone service."

    2. Re: Probably some telphone code by kenh · · Score: 2

      Don't look to the US for sympathy - we paid a tax on our phone service for over a century to pay off the Spanish American War... 108 years to be precise !

      http://usatoday30.usatoday.com/money/industries/telecom/2006-05-25-phone-tax_x.htm

      --
      Ken
  13. ob by Hognoxious · · Score: 4, Funny

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

    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  14. Highest number of executions by Anonymous Coward · · Score: 2, Interesting

    The keyboard scan loop in Windows gets my vote.

  15. Re:Bitcoin by The+Mighty+Buzzard · · Score: 4, Informative

    If it's not yet, it will be soon. At the moment the SHA-256 algorithm is being run in the neighborhood of 15,000,000,000,000,000 times per second by miners.

    --
    Violence is like duct tape. If it doesn't solve the problem, you didn't use enough.
  16. Scrypt by mysidia · · Score: 2, Interesting

    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;

    }

  17. Re:Solved. Next? by Fnordulicious · · Score: 2

    It’s not really executable as I understand it, but I am not a biologist. The translation from DNA to RNA is hard to construe as ‘execution’. Then in the next step the RNA goes to ribosomes to construct proteins. So maybe DNA is ‘compiled’?

    The field of computational biology would probably have a good metaphor to map the ideas from biology to computer science.

  18. Re:Solved. Next? by Anonymous Coward · · Score: 2, Insightful

    Perhaps it would be better to say for most genes that you compile a protein from the DNA using a temporary (RNA) copy and your ribosomes as the compiler, and the protein is the executable version ... although the ribosomal RNA genes are the most ancient still used and among the few that few active components that are still used in RNA form (tRNAs as carriers probably would not count).

  19. Clock counting loops by msobkow · · Score: 2

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

    --
    I do not fail; I succeed at finding out what does not work.
  20. Re:Solved. Next? by Anonymous Coward · · Score: 3, Interesting

    It's not compiled, it's interpreted. If you had a single gigantic mRNA consisting of all your genes, that would be compilation.

    You can think of DNA as source (in an extremely low-level language), mRNA as machine code, and ribosomes as microcontrollers. DNA transcriptase interprets DNA into RNA. In eukaryotes, SNRPs are optimizers (written by a lunatic, but no analogy is perfect) that rearrange the RNA; ribosomes interpret the RNA.
    You've got lots of ribosomes in each cell, so think of each cell as a massively multi-core architecture running a totally asynchronous program.

    So what's the most frequently interpreted gene? Most likely something used by bacteria, since those are the most numerous cells on the planet. Or maybe a routine that's common to all cells. Something that regulates cell division?

    Note that a lot of the stuff that cells do most frequently (say, transport a hydrogen ion across a membrane) does not require DNA synthesis each time. The instructions in DNA are in large part "build a machine out of protein"; there are also a lot of genes involved in *managing* the machine but not much involved in *operating* the machine, if you see what I'm driving at. Obviously, after cell division you need to synthesize more stuff to replace what you've lost (otherwise you'd shrink away to nothing after surprisingly few divisions), but you basically need to sythesize everything; I'm not sure one gene would stand out.

    There are specialized cases where a cell needs to synthesize LOTS of something; salivary glands in insects for example make lots of extra copies of the genes for certain enzymes; some plants do something similar to synthesize various chemicals. But these cases are probably outnumbered by bacteria.

  21. Windows.Reboot() by mtthwbrnd · · Score: 2

    followed closely by...
    Java.InstallUpdate()