A Python finds out which is the best performing Linux distro!

python

With more and more linux distributions competing among themselves for the userspace, we are currently living in the best of times as far as choice in open-source software is concerned. However, more the number of choices, more is the head-scratching to decide what to choose amongst them. Like many, I am also one of the victims of “distro-hopping”. No sooner a major distribution declares a new version, I’m itching to try one out in my virtual box or as a LiveCD version. Few days ago, this benchmarking idea occurred to me.

I’m a software developer and my requirements were clear. I wanted a distro that is good at performance. Since my desktop is cluttered with “heavy-duty” programs like Eclipse-ADT, Java, IDLE, etc., performance was my primary concern. I mostly write application software and android apps, so things like disk I/O, memory and CPU utilization matter.

With these things in my mind, I was seeking a simple way to do a quick benchmark of various distros to find out what suits my needs. Thats when this idea came to me – Almost all distros come preloaded with a general-purpose scripting language called python which could be summoned for the job. I took “time taken in milliseconds” to do 5 basic tasks to decide on the performance. These tasks were:

  1. Zip-test: A test to compress a large file to a zip file, and extract in back in python code.
  2. Random-test: Generate 5 million random numbers and round them to zero decimals.
  3. I/O test: Write a unicode string ‘spam and eggs’ 5 million times to a text file, and read them back.
  4. CSV test: Generate a CSV spreadsheet with 5 million rows in it, and read them back.
  5. Bandwidth test: Download the 800K akonadi RPM file from IIT Kanpur’s website.

(The last one was just for the sake of completeness. Internet bandwidth depends more on other parameters such as your ISP limits, time of the day, latency, etc. rather than the disto you are using).

The contestants in the arena were:

  1. openSUSE 12.2
  2. Debian 7 (GNOME version)
  3. Fedora 18
  4. Ubuntu 12.04 LTS
  5. Xubuntu 12.04

My previous experience with Ubuntu made be biased towards it, but the tests showed me how wrong I was. Also, from what I’d read in most blogs on the Internet, KDE was one of the most bloated distros ever. However, in my tests KDE on openSUSE topped the race in most parameters, though the credit should go to openSUSE for optimizing the KDE. The second spot saw Fedora and Debian fighting amongst them, while Ubuntu (that I was presently using) fared the worst! Here are the detailed results:

Test zt1

(compress)

zt2

(archive)

random io csv bandwidth
debian1 7622 2753 9142 5732 12784 118978
debian2 7724 2752 9161 5287 12112 92386
fedora18_1 8605 4168 6287 5972 12750 0
fedora18_2 7762 4164 6419 6160 12818 0
openSUSE1 9001 2313 5915 5904 12715 115999
openSUSE2 7253 2245 6035 5935 11492 71257
precise1 9649 5012 8807 6846 13552 78560
precise2 10555 4434 8890 7229 13455 48286
xubuntu1 13305 4827 8954 5839 14676 58538
xubuntu2 10826 4760 8934 7908 12802 52768

*Above figures represent time-taken in milliseconds

The bandwidth test could not be performed on fedora as the Live CD did not have the wget package installed, but I did not need that to get a general idea of things.

My Conclusion: openSUSE wins the race, though Debian-7 and Fedora-18 are also fine distros for performance.

Here is the entire python benchmarking script that you may customize as per your requirement (change initializing variables in the script and run by issuing “python benchmark.py” from the shell):

 

import sys,time,os
import zipfile,random,csv
import subprocess
from zipfile import ZipFile,ZIP_DEFLATED
from random import random

##Variables
#This should be initially present before running the program:
test_name=’debian1′
file_to_extract = “VirtualBox.exe” #”dotnetfx35.exe”
##

def timer(test):
t1=time.time()#.clock()
elapsed=0
#
if test == “ziptest1”:
ziptest1()
elif test == “ziptest2”:
ziptest2()
elif test == “randomtest”:
randomtest()
elif test==”iotest”:
iotest()
elif test==”csvtest”:
csvtest()
elif test==”bwtest”:
bwtest()

elapsed=time.time()-t1
timetaken=round(elapsed*1000,0)
print test,timetaken,”msecs.”
return timetaken

def ziptest1():
myzip=zipfile.ZipFile(‘t.zip’,’w’,ZIP_DEFLATED) #ZIP_STORED
myzip.write(file_to_extract)
myzip.close()
return

def ziptest2():
os.remove(file_to_extract)
myzip=zipfile.ZipFile(‘t.zip’,’r’)
myzip.extractall()
myzip.close()
return

def randomtest():
for i in range(1,5000000):
r = round(random()*100,0);
#print r
return

def iotest():
file=open(‘myfile1k.txt’,’w’)
for i in range(1,5000000):
file.write(u’spam and eggs’)
file.close()
#
file=open(‘myfile1k.txt’,’r’)
s=file.readline()
while (s!=”):
#print s
s=file.readline()
file.close()
return

def csvtest():
file=open(‘myfile.csv’,’w+b’)
#
writer= csv.writer(file,delimiter=’,’,quotechar=’|’)#,quoting=csv.QUOTE_MINIMAL)
for i in range(1,5000000):
writer.writerow([‘spam’,’eggs’,’spam1′])
#writer.close()
file=open(‘myfile.csv’,’r+b’)
reader=csv.reader(file,delimiter=’,’,quotechar=’|’)
for row in reader:
s= ‘,’.join(row)
#reader.close()
#
file.close()
return

def bwtest():
subprocess.call([“wget”,”http://mirror.cse.iitk.ac.in/fedora/releases/18/Fedora/i386/os/Packages/a/akonadi-1.8.1-1.fc18.i686.rpm”,”-O akonadi.rpm”])
#subprocess.call([“wget”,”http://www.google.com”,”-O”,”akonadi.rpm”])
return

if __name__ == “__main__”:
#print time.strftime(“%d-%m-%y %H:%M”, time.gmtime())
#print time.strftime(“%d-%m-%y %H:%M”, time.localtime())
zt1=timer(“ziptest1”)
zt2=timer(“ziptest2”)
random=timer(“randomtest”)
io=timer(“iotest”)
cst=timer(“csvtest”)
bw=timer(“bwtest”)

#Store results to csv file.
file=open(‘results.csv’,’ab’)
writer= csv.writer(file,delimiter=’,’,quotechar=’|’)
#writer.writerow([‘test’,’zt1′,’zt2′,’random’,’io’,’cst’,’bw’])
writer.writerow([test_name,zt1,zt2,random,io,cst,bw])
file.close()
print ‘\n\nWritten results.csv’
#
exit(0)

Fedora vs Ubuntu vs Linux Mint for Performance

Fedora vs Ubuntu vs Linux Mint

The never ending search for that “holy grail” distribution keeps most people downloading and hopping from one distro to another without ever bothering to ask themselves why they want to use an operating system in the first place. I don’t blame them, as nowadays, the ever active “assembly-lines” of various distro factories like ubuntu, fedora and linux-mint are enough to boggle the minds of most newbies by throwing an enormous number of configuration options.

Until some time ago, I myself was one of those “holy grail” seekers endlessly installing one distro after another in the second partition of my hard drive which is always reserved for Linux. Since my full time job involves .NET programming for my organization, I have to keep the first one reserved for Win7 of course.

Anyways, coming back to my Linux endeavors, I decided to pause and look inwards. I asked myself why do I want to use Linux? Thats because I want to: 1) Learn and understand the Linux operating system and programs using a top-down approach, and 2) Learn programming on Linux – this involves a lot of things including C++, GTK+, Qt, Android and the suchlike, and 3) Doing miscellaneous things such as listening to music, some light gaming, etc.

The most obvious thing that occurred to me was one word – performance. I don’t need high-end graphics. I’m never getting into serious gaming stuff such as OpenGL. All I need is a distro that can handle as many applications and programs as I can throw at it. Since I don’t have time for doing things from scratch like LFS or ArchLinux, I shortlisted the below three candidates:

1. Ubuntu 12.04 LTS – Precise Pangolin

2. Linux Mint 14.1 – Nadia

3. Fedora 18 – Spherical Cow

Rather than search for existing benchmarks, I decided to put these gladiators in my own arena. I prepared my 16GB pendrive for a multi-boot with the above three Live versions and started testing them one by one. The stuff I threw at them was things I would normally do, such as extracting a huge (4GB) archive, format a USB pendrive, surf the net, etc. Here is how each one of them fared in the fight:

Distro Benchmarking

The verdict: Unlike the gladiators of Rome where one used to absolutely dominate over the other, the case of these linux distros is entirely different. One distro fared well in one area, while the other fared in another. For instance, Fedora was good at CPU usage, while Linux-mint did well in the RAM area. However, for my purposes, I regard Linux-mint as an ideal choice overall.

Some free tools to help you develop better .NET Solutions!

1. DebugView: DebugView is a free tool that lets you view the debug output written by applications on the windows operating system. You might be aware that many Try/Catch blocks in .NET applications use the Debug.WriteLine statement to make note that an error or exception occurred. DebugView displays an output log of all such diagnostics written by your application thus making the task of tracking errors much easier. In fact, on live or production systems, it is not always possible to run your application in debug mode. In such cases, DebugView comes very handy as it lets you see the exceptions written by your .NET application without disrupting any user activity.

http://www.sysinternals.com/Utilities/DebugView.html

2. FxCop: For those who wish to follow the industry best-practices while coding .NET applications, this free tool from Microsoft is a great boon. FxCop helps you with code-review by analyzing your .NET assembly and highlighting several programming and design issues such as:

  • Not following proper naming-conventions for constants and variables.
  • Improper commenting of code.
  • Inappropriate use of public variables.
  • Using obsolete or irregular keywords like goto.
  • Performance issues (use of excessive locals, declaring unused parameters, etc.)
  • Security issues (not specifying marshalling for pinvoke string arguments, etc.)
  • Design issues (Not strong-naming an assembly, hiding base-class methods, etc.)

To see a complete list of FxCop rules with an in-depth discussion and example, see msdn:

http://msdn.microsoft.com/en-us/library/bb429379(v=vs.80).aspx

3. StyleCop: StyleCop is another opensource tool for static code analysis. It analyzes the C# source-code unlike FxCop which analyzes the assembly. It thus applies a different set of rules from FxCop. These rules fall in seven basic categories:

  • Documentation
  • Layout
  • Maintainability
  • Naming
  • Ordering
  • Readability
  • Spacing

4. CLR Profiler:CLR Profiler is an excellent tool to help you identify performance issues in your .NET application. Many a times it so happens that you notice your application is performing poorly or consuming a lot of memory, but could not put your finger on the exact function or class in code that is causing this. This tool does exactly that! It creates a call graph analysis when your .NET application is run, along with the behaviour of the Grabage-Collector. CLR Profiler is a free download from Microsoft:

Download CLR-Profiler from Microsoft

5. NANT: NANT is a free and opensource tool for automating the software build process.  NANT is specifically targetted at building .NET solutions. It automatically fetches the dependency tree and builds them in order for your .NET solution. NANT is free software:

http://nant.sourceforge.net/

6. Subversion/TortoiseSVN: Subversion is an excellent opensource collaboration software used by several large firms to manage inhouse development in large teams. Subversion is the server component that provides a central repository to store your .NET code, while there are several Subversion clients (TortoiseSVN being the most popular) that integrate with your windows-shell and provide SCM features and tools to:

  • Check-out, browsing and check-in of code in the SVN repository.
  • View change log and changes made by other users to the repository.
  • Compare or merge your local code with the base version in repository.
  • Resolve conflicts (if any) with the base version by gradually accepting/rejecting the changes.

Both Subversion and TortoiseSVN are 100% free and opensource:

http://subversion.tigris.org/
http://tortoisesvn.net/downloads.html

7. Redgate Reflector: Not many people know that the EXE or DLL compiled from your Visual-Studio IDE is prone to reverse-engineering if you ship them as it is. That is because, a .NET assembly (EXE/DLL) is not directly compiled to the low-level machine code, but rather, into CIL (Common Intermediary Language) to achieve architecture independence and reduce compile time. One such industry-standard tool to reverse engineer a .NET assembly is the Redgate Reflector. Reflector takes the .NET assembly as input and regenerates the entire source-code and solution in the language of your choice (VB/C#/F#/etc). Though Reflector is a commercial product, you can use the free demo version to decompile .NET assemblies (but with some limitations):

http://www.reflector.net/

8. AnkhSVN/SharpSVN: AnkhSVN is yet another opensource tool which is managed by Collabnet, the creators of  SVN Server itself. It seamlessly fits into the Visual Studio IDE and allows you to check-out and commit code to your SVN repositories. Also, the api used by SVN called SharpSVN is also an opensource .NET 2.0 library. You can add its reference to your .NET project if you need to automate code check-outs and commits from your application itself:

http://sharpsvn.open.collab.net/

9. Windows SDK Tools: You can find a bunch of usefull stuff already installed in your Windows SDK directory itself! These are typically installed in the below folder:

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\

sn.exe is the strong-name utility that you can use to strong-name your .NET assemblies.

gacutil.exe is used to install/uninstall an assembly from the .NET GAC (Global Assembly Cache).

wsdl.exe automatically generates .NET code for xml web-service clients to connect to a web-service.

svcutil.exe pregenerates C# serialization code that is required for types that can be serialized using XML Serializer.

ildasm.exe is a disassembler that generates CIL code from .NET assemblies.

References:

http://en.wikipedia.org/wiki/.NET_Reflector
http://en.wikipedia.org/wiki/StyleCop
http://en.wikipedia.org/wiki/CLR_Profiler
http://en.wikipedia.org/wiki/NAnt
http://en.wikipedia.org/wiki/AnkhSVN