I was so bored the other day, that I wrote a fat client in C# to calculate happy numbers. I used BackgroundWorker class, because I was hoping to be able to cancel the calculation process. It turned out I couldn't. Rats.

Out of pure frustation, I wrote the same program in Java using Swing and SwingWorker. Here, the cancel feature worked just fine.

And then I had this "Wait ... What?!" moment, when I realized, that one of the programs was incredible slow. So I rewrote both codes, so that they used the same algorithm and similar classes. I compiled the C# program as release and ran it stand-alone, while I started the Java application from within the eclipse IDE.

The C# program needed 42.681 seconds for 100,000 happy numbers, while the Java application completed the same task after 0.986 seconds. The result sets of both programs are the same.

Maybe I need a new PC (2007, 64 bit, 8 GB RAM, Windows 10). Or I'll get rid of C#.

  • 4
    Github or it didn't happened
  • 0
    Happy numbers ?
  • 0
  • 1
    @Framstag I might need source cOde for this one
  • 3
    And cancelation is a possibility, you have to implement it in C#
  • 1
    @sam9669 It's more of an "I'm bored, what can I do to waste time?" code, so it's free of MVC and other patterns. And I didn't post this for an advice, but as an anecdote.

    In the office, I write C# code since 2002 in different flavours (fat clients, web applications, Windows services, web services ...). At home, I prefer Java and Python, because I use Windows, Linux, and macOS.
  • 0
    @Framstag do you still live in 2002 and don't know of Mono?
  • 0
    @QCat I know, because I had used that class several times before. But this time not even breakpoints seemed to stop the execution.
  • 0
    @QCat I gave Mono a try in 2011, but it didn't convince me at all. Plus, I like Java and Python.
Add Comment