Content-Type: RST Some of my friends here at college have started taking the introductory class for C++, and one of them put the general opinion thus: "C++ makes me love Python". Syntax-wise the jump from Python to C++ is pretty terrible, indeed. However, I gave him the usual stuff about how C++ is faster and more efficient. However, I'm not sure that argument is valid anymore. .. figure :: http://blog.opensourcenerd.com/upload/shocked-cat I know, right? After telling him this is I wanted some conclusive evidence that C++ is indeed faster, to better prove my point. So, I rigged up a quick test. First, I got the names of all of Ubuntu's system files and put them in "files.txt". .. sourcecode :: sh $ find /usr > files.txt $ wc -l files.txt 151246 files.txt 151246 lines, that's a fair number. Next, I run this Python script to shuffle them: .. sourcecode :: python from random import shuffle fnames = open('files.txt').read().split() shuffle(fnames) out = open('files.txt','w') for x in fnames: out.write(x+'\n') out.close() Then, I wrote two versions of a **bubble sort**, the slowest kind of "standard" sort algorithms, but easy to code. What it consists of is looping over the list of items to be sorted, and if it finds any two items that are out of order, it swaps them. If there were no swaps done on an iteration, that means it's done, and it stops. I implemented this in Python: .. sourcecode :: python def bubble(names): swapped = False for i in range(0,len(names)-1): if names[i]>names[i+1]: names[i], names[i+1] = names[i+1], names[i] swapped = True return swapped names = open('files.txt').read().split() while not bubble(names): pass out = open('sorted.txt', 'w') for x in names: out.write(str(x) + '\n') out.close() ... and in C++: .. sourcecode :: cpp #include #include #include using namespace std; bool bubble(vector& names) { bool switched = false; for(vector::iterator it=names.begin(); it **(it+1)) { string* tmp = *it; *it = *(it+1); *(it+1)= tmp; switched = true; } return switched; } int main() { ifstream in("files.txt"); vector names; string x; while (in >> x) names.push_back(new string(x)); while (!bubble(names)) continue; ofstream out("sorted.txt"); for(vector::iterator it=names.begin(); it