Skip to content

Archive

Tag: Mono

That’s right an update to your favourite hash verification program! :P

This update includes a few new features that some of you might find useful. It also includes help documentation which walks you through how to use it!

New Features

  • Menu strip for even easier use
  • Export features allows you to automatically write all of the hashes to a single file
  • About dialog that provides information about the program
  • Help documentation

Requirements:

  • All platforms: .NET 2.0+ / Mono, a graphical display
  • *nix platforms: WinForms (identified as System.Windows.Forms)

As always the binary only package contains just the executable, whereas the all package contains the source code as well.

Binary Only Package All Package
File name: hash_verifier_0_2_0_0_binary.zip hash_verifier_0_2_0_0_all.zip
File hashes: Download Here
GPG signature: Download Here Download Here
Screenshots: Screenshot 1 Screenshot 2
License: (LGPL) View Here
Version: 0.2.0.0
File size: 171.5KB 530.1KB
File download: Download Here Download Here

As someone who has recently begun to experiment with the Linux operating system I have also been introduced to .NET’s Linux’s cousin Mono. This has made me question what the best cross-platform program language to use is. I am familiar with both Java and various .NET languages (Visual Basic & C#) so I decided to run a few tests to see what the resource usage on my Linux laptop is like between these two competing platforms.

Hardware

CPU Information

  • Processor (CPU): Intel Core2Duo CPU P8600 @ 2.40GHz

Memory Information

  • Total Memory (RAM): 4GiB
  • Swap Partition Size: ~6GiB

OS Information

  • OS: Linux 2.6.30.9-102.fc11.x86_64
  • System: Fedora  11
  • Desktop Environment: KDE 4.3.3

Display Info

  • Model: ATI Mobility Radeon HD 4670
  • Driver: 2.1.9026 FireGL

Hard Drive Info

  • Memory: 320GiB 7,200 RPM SATA

Software

I am using Java version 1.6.0 and Mono version 2.4.2.3 for these tests.

Test Setup

For the following tests I have provided source code for both the Java and the C# implementations. I then ran the programs and checked their CPU and memory usage.

Test I

Simple write/read test to the console. CPU usage was recorded before the read.

Java code:

import java.io.IOException;

public class TestI {

     public static void main(String[] args) {

          System.out.println(“Hello World”);

          try {
               System.in.read();
          } catch (IOException e) {
               e.printStackTrace();
          }
     }

}

C# code:

using System;

namespace TestI
{
     class MainClass
     {
          public static void Main(string[] args)
          {
               Console.WriteLine(“Hello World!”);

               try {
                    Console.Read();
               }catch(Exception e){
                    Console.Write(e.StackTrace);
               }

          }
     }
}

Results:

Java C#
Memory Usage: 5.6MiB 2.2MiB
CPU Usage: 0% 0%

Test II

Simple primitive variable usage. CPU usage was recorded before the read.

Java code:

import java.io.IOException;

public class TestII {

     public static void main(String[] args) {

          byte b = 0;
          short s = 0;
          int i = 0;
          long l = 0;
          float f = 0;
          double d = 0;
          boolean bo = true;
          char c = ‘a’;

          //set them all to something
          b = 1;
          s = 1;
          i = 1;
          l = 1;
          f = 1;
          d = 1;
          bo = false;
          c = ‘b’;

          try {
               System.in.read();
          } catch (IOException e) {
               e.printStackTrace();
          }

     }

}

C# code:

using System;

namespace TestII
{
     class MainClass
     {
          public static void Main(string[] args)
          {
               byte b = 0;
               short s = 0;
               int i = 0;
               long l = 0;
               float f = 0;
               double d = 0;
               bool bo = true;
               char c = ‘a’;

               //set them all to something
               b = 1;
               s = 1;
               i = 1;
               l = 1;
               f = 1;
               d = 1;
               bo = false;
               c = ‘b’;

               try {
                    Console.Read();
               }catch(Exception e){
                    Console.Write(e.StackTrace);
               }
          }
     }
}

Results:

Java C#
Memory Usage: 5.6MiB 2.1MiB
CPU Usage: 0% 0%

Test III

Simple primitive variable usage, this time with arrays. Same as above but with arrays of 10,000 for each primitive. The arrays were set using loops similar in structure to the following:

for(int x=0; x<10000; x++)
{
     b[x] = 1;
}

Results:

Java C#
Memory Usage: 5.9MiB 2.4MiB
CPU Usage: 0% 0%

Test IV

Simple object usage. CPU usage was recorded before the read.

Java code:

import java.io.IOException;

public class TestIV {

     public static void main(String[] args) {

          SimpleClass sc = new SimpleClass();

          sc.setID(5);
          sc.setName(“Hello World”);

          System.out.println(sc.getString());

          try {
               System.in.read();
          } catch (IOException e) {
               e.printStackTrace();
          }
     }

}

public class SimpleClass {

     private int _ID;
     private String _name;

     public SimpleClass()
     {
          //default constructor
     }

     public SimpleClass(int ID, String name)
     {
          _ID = ID;
          _name = name;
     }

     public int getID()
     {
          return _ID;
     }

     public void setID(int ID)
     {
          _ID = ID;
     }

     public String getString()
     {
          return _name;
     }

     public void setName(String name)
     {
          _name = name;
     }
}

C# code:

using System;

namespace TestIV
{
     class MainClass
     {
          public static void Main(string[] args)
          {
               SimpleClass sc = new SimpleClass();

               sc.setID(5);
               sc.setName(“Hello World”);

               Console.WriteLine(sc.getString());

               try {
                    Console.Read();
               }catch(Exception e){
                    Console.Write(e.StackTrace);
               }
          }
     }
}

using System;

namespace TestIV
{

     public class SimpleClass
     {

          private int _ID;
          private String _name;

          public SimpleClass()
          {
               //default constructor
          }

          public SimpleClass(int ID, String name)
          {
               _ID = ID;
               _name = name;
          }

          public int getID()
          {
               return _ID;
          }

          public void setID(int ID)
          {
               _ID = ID;
          }

          public String getString()
          {
               return _name;
          }

          public void setName(String name)
          {
               _name = name;
          }

     }
}

Results:

Java C#
Memory Usage: 5.6MiB 2.2MiB
CPU Usage: 0% 0%

Test V

Simple object usage, this time with arrays. Same as above but with arrays of 10,000 for each object. The arrays were set using loops similar in structure to test III:

Java code:

import java.io.IOException;

public class TestV {

     public static void main(String[] args) {

          SimpleClass[] sc = new SimpleClass[10000];

          for(int x=0; x<10000; x++)
          {
               sc[x] = new SimpleClass();
               sc[x].setID(5);
               sc[x].setName("Hello World");

               System.out.println(sc[x].getString());
          }

          try {
               System.in.read();
          } catch (IOException e) {
               e.printStackTrace();
          }
     }

}

C# code:

using System;

namespace TestV
{
     class MainClass
     {
          public static void Main(string[] args)
          {
               SimpleClass[] sc = new SimpleClass[10000];

               for(int x=0; x<10000; x++)
               {
                    sc[x] = new SimpleClass();
                    sc[x].setID(5);
                    sc[x].setName("Hello World");

                    Console.WriteLine(sc[x].getString());
               }

               try {
                    Console.Read();
               }catch(Exception e){
                    Console.Write(e.StackTrace);
               }
          }
     }
}

Results:

Java C#
Memory Usage: 10.1MiB 2.6MiB
CPU Usage: 8% 2%

Test VI

Everyone’s favourite bubble sort with 10,000 integers.

Java code:

import java.io.IOException;

public class TestVI {

     public static void main(String[] args) {

          int[] array = new int[10000];

          //fill array
          for(int i=0;i           {
               array[i] = 10000-i;
          }

          boolean swapped;

          do
          {
               swapped = false;

               for(int i=0;i                {
                    if(array[i] > array[i+1])
                    {
                         int temp = array[i+1];
                         array[i+1] = array[i];
                         array[i] = temp;

                         swapped = true;
                    }
               }
          }while(swapped);

          System.out.println(“Sorted”);

          try {
               System.in.read();
          } catch (IOException e) {
               e.printStackTrace();
          }
     }

}

C# code:

using System;

namespace TestVI
{
     class MainClass
     {
          public static void Main(string[] args)
          {
               int[] arr = new int[10000];

               //fill array
               for(int i=0;i                {
                    arr[i] = 10000-i;
               }

               bool swapped;

               do
               {
                    swapped = false;

                    for(int i=0;i                     {
                         if(arr[i] > arr[i+1])
                         {
                              int temp = arr[i+1];
                              arr[i+1] = arr[i];
                              arr[i] = temp;

                              swapped = true;
                         }
                    }
               }while(swapped);

               Console.WriteLine(“Sorted”);

               try {
                    Console.Read();
               }catch(Exception e){
                    Console.Write(e.StackTrace);
               }
          }
     }
}

Results:

Java C#
Memory Usage: 6.3MiB 2.2MiB
CPU Usage: 6% 12%

All Results

Java C#
Test I Memory Usage: 5.6MiB 2.2MiB
Test I CPU Usage: 0% 0%
Test II Memory Usage: 5.6MiB 2.1MiB
Test II CPU Usage: 0% 0%
Test III Memory Usage: 5.9MiB 2.4MiB
Test III CPU Usage: 0% 0%
Test IV Memory Usage: 5.6MiB 2.2MiB
Test IV CPU Usage: 0% 0%
Test V Memory Usage: 10.1MiB 2.6MiB
Test V CPU Usage: 8% 2%
Test VI Memory Usage: 6.3MiB 2.2MiB
Test VI CPU Usage: 6% 12%

Conclusions

Well there you have it. It seems that at this point in time Mono is not only mature enough to compete against a seasoned veteran programming language like Java, but in some cases good enough to even supersede it. This is wonderful news for people looking for alternative cross-platform high level languages.

Some of you may remember an old Windows program of mine called Hash Verifier. It was a graphical utility that allowed people to generate hashes of their files, and then compare those to known hashes, ensuring that their files had not been corrupted. Well in recent months my foray into the world of Linux has finally taken me into the realm of programming on that platform. Being primarily a .NET developer on Windows I have found the Mono project on Linux to be an absolute breath of fresh air.

“Monkey” project

The Mono project is an open source implementation of Microsoft’s .NET common language runtime and a C# compiler. On Linux the easiest way to program in a Mono language is within the project’s own integrated development environment called MonoDevelop.

C is a sharp language

C# is a very powerful programming language that falls somewhere between C and Java in terms of syntax. While my experience with C# has been limited in the past, I was easily able to pick it up quickly thanks to my background in both C and Java, as well as fellow .NET language Visual Basic.

The challenge

Digging up an old .NET project of mine, Hash Verifier, I decided to challenge myself to port the application to Mono. In order to do this I needed to accomplish the following:

  • The original application ran on Microsoft’s .NET on the Windows platform. The new application must run on both .NET on Windows and Mono on supported platforms.
  • The original application was written in Visual Basic. The new application must be written in C#.
  • The original application has a GUI powered by the native Windows.Forms. The new application needs to have a GUI that works in a similar way on all platforms.
  • The new application must be able to fully re-create all of the old application’s features and functions.

Porting = easy

I must say that porting this old application to C#/Mono was a relatively straightforward task. Although I had plenty of GUI toolkits to choose from I ended up sticking with the existing Windows.Forms. Once I had decided on using Windows.Forms as the basis for my GUI (WinForms is a free and open source implementation for non-Windows users!) I set out to create my new application. I was literally able to open the old Visual Basic GUI designer file, copy the code into my Mono workspace, change the syntax to C# and voila it worked!

In fact the only tricky part was trying to figure out a compatibility issue that .NET/Mono 2.0 seem to have with the new Windows Presentation Foundation (WPF). I’ll save you the gory details but basically drag and drop functionality would not work. I eventually rectified this issue by including a compiler flag telling .NET/Mono to execute the form in single thread apartments mode. You can see where I did this in my code by looking right above my static main function:

[STAThreadAttribute]
public static void Main()
{

}

Final result

With the application complete I must say I am impressed. Crafting and running applications for Mono is extraordinarily simple to do, seems very powerful, and the application itself only takes up a couple of MiB to run. In the future I definitely plan on doing more of this type of development now that I am using different operating systems every day.

Hash Verifier

If you are still using the old version of Hash Verifier, or if you would just like to try it out you can download the new Hash Verifier in two different ways. The package marked binary only contains just the program itself and the relevant documentation. The package marked all contains both the program, documentation as well as the source code.

Requirements:

  • All platforms: .NET 2.0+ / Mono, a graphical display
  • *nix platforms: WinForms (identified as System.Windows.Forms)
Binary Only Package All Package
File name: hash_verifier_0_1_0_0_binary.zip hash_verifier_0_1_0_0_all.zip
File hashes: Download Here
GPG signature: Download Here Download Here
License: (LGPL) View Here
Version: 0.1.0.0
File download: Download Here Download Here