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 Insider News
  4. Yes, PHP is faster than C#

Yes, PHP is faster than C#

Scheduled Pinned Locked Moved The Insider News
csharpphptutorial
6 Posts 6 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.
  • K Offline
    K Offline
    Kent Sharkey
    wrote on last edited by
    #1

    A walk within boredom[^]:

    There’s something very common that all developers must do, and that is read files… we need to parse things, transform file formats, or whatever. So, let’s compare the two languages.

    * for one highly contrived example

    J S T realJSOPR 4 Replies Last reply
    0
    • K Kent Sharkey

      A walk within boredom[^]:

      There’s something very common that all developers must do, and that is read files… we need to parse things, transform file formats, or whatever. So, let’s compare the two languages.

      * for one highly contrived example

      J Offline
      J Offline
      Joe Woodbury
      wrote on last edited by
      #2

      One badly written example *and* he turned off optimizations. The algorithms don't even match (apologies to the UK.)

      1 Reply Last reply
      0
      • K Kent Sharkey

        A walk within boredom[^]:

        There’s something very common that all developers must do, and that is read files… we need to parse things, transform file formats, or whatever. So, let’s compare the two languages.

        * for one highly contrived example

        S Offline
        S Offline
        Super Lloyd
        wrote on last edited by
        #3

        well.. he read by chunk of 4096 byte buffer in PHP, and 1 byte at a time in C#, doing 4096 more I/O operation in C#, yet times are comparable! :O Conclusion, C# I/O blows PHP by a factor of 4096! :O

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        O 1 Reply Last reply
        0
        • S Super Lloyd

          well.. he read by chunk of 4096 byte buffer in PHP, and 1 byte at a time in C#, doing 4096 more I/O operation in C#, yet times are comparable! :O Conclusion, C# I/O blows PHP by a factor of 4096! :O

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          O Offline
          O Offline
          obermd
          wrote on last edited by
          #4

          Don't forget the PHP version is reading the file in binary and the C# version is converting the binary stream into Unicode characters.

          1 Reply Last reply
          0
          • K Kent Sharkey

            A walk within boredom[^]:

            There’s something very common that all developers must do, and that is read files… we need to parse things, transform file formats, or whatever. So, let’s compare the two languages.

            * for one highly contrived example

            T Offline
            T Offline
            trønderen
            wrote on last edited by
            #5

            It is years since I last heard it: "First, there are lies. Then there are d**m lies. And then comes benchmarks." But why did that old truth come to mind now?

            1 Reply Last reply
            0
            • K Kent Sharkey

              A walk within boredom[^]:

              There’s something very common that all developers must do, and that is read files… we need to parse things, transform file formats, or whatever. So, let’s compare the two languages.

              * for one highly contrived example

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              I did a c# only test (running in VS 2017 in a Win7 VM). Omitting file reading time, and conversion to text (for the string counters, and conversion to a byte array for the stream counting), I only timed the actual time required to count the occurrences of '1'. I averaged three runs for each situation. 0) The chosen file was a paintshop pro image file that was 4,046,848 bytes large. 1) I wrote a string (and MemorySream) extension method for each of the three counting styles. 2) Each count run was executed three times per counting style, and the result was averaged. 3) The duration calculation only included the actual time it took to count the number of '1' characters in the string/stream. Any conversion code that was performed was not included i the duration calculation. I found that the reported durations were *all over the map*. For instance, counting as a string with a .Where call took from 44ms to 147ms. All counting styles exhibited this behavior. However, some general observations could be made: 0) Using some variation of linq collection.Where(x=>x == '1') was always the slowest code. 1) Counting with a foreach loop was almost twice as fast for strings as using .Where, but streams were only about 1/3 faster than their string counterparts. 2) Counting with a normal for took about the same amount of time as the foreach code (the difference was +/- 2 ms. Again, the actual reported durations were all over the map, so mentioning them specifically would be kinda pointless. My considered opinion is that this article is just more bullshit from someone that tried to be a programmer and couldn't pull it off, so now he writes articles about programming, telling us (actual programmers) how we should do it.

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

              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