I wrote a small recursive algorithm to generate all permutations/combinations of a string with any of 89 characters. On my linux box with a core 2 duo and 2 gigs of ram, the program runs exponentially faster than on my imac with an i7 processor and 4 gigs of ram.
I took a look at the processor usage on the mac and it's around 13%.
I read somewhere that the disk IO on OSX takes longer than on linux, so I removed all the writing to the disk and the program is simply generating strings, not storing them anywhere.
When I run the program with the clock command on the two separate systems, the output is like this:
Linux
1 10000
2 10000
3 10000
4 110000
5 9640000
OSX 10.6.2
1 3043
2 4377
3 125890
4 9480674
Where the number on the left is the number of characters allowed in the string and the number on the right is the output of the clock function. You'll notice that 5 is missing from the mac section. This is because after 10 minutes, the mac had not finished generating strings of length 5. The linux box with inferior raw computing power generated strings of length 5 in under 30 seconds.
here is the code, it is exactly the same on both machines
any ideas why my i7 powered osx machine is being so severely whipped by my core 2 duo linux machine?
thanks,
Mike
I took a look at the processor usage on the mac and it's around 13%.
I read somewhere that the disk IO on OSX takes longer than on linux, so I removed all the writing to the disk and the program is simply generating strings, not storing them anywhere.
When I run the program with the clock command on the two separate systems, the output is like this:
Linux
1 10000
2 10000
3 10000
4 110000
5 9640000
OSX 10.6.2
1 3043
2 4377
3 125890
4 9480674
Where the number on the left is the number of characters allowed in the string and the number on the right is the output of the clock function. You'll notice that 5 is missing from the mac section. This is because after 10 minutes, the mac had not finished generating strings of length 5. The linux box with inferior raw computing power generated strings of length 5 in under 30 seconds.
here is the code, it is exactly the same on both machines
Code:
#include <stdlib.h>
#include <iostream>
//#include <iomanip>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <fstream>
#include <ctime>
using namespace std;
//10+26+26+27 = 89 CHARACTERS
void Tokenize(const string str,
vector<string>& tokens,
const string& delimiters = "-")
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
void generatePasswords(int depth,char chars[89], string passwd, vector<string> start, vector<string> stop)
{
for(int x = atoi(start[depth].c_str()); x<atoi(stop[depth].c_str()); x++)
{
string currpass = passwd + chars[x];
if(depth!=0)
{
generatePasswords(depth-1, chars, currpass, start, stop);
}
else
{
//cout<<currpass<<endl;
//ofstream file;
//file.open("test.txt",ios::app);
//file <<currpass<<endl;
//file.close();
}
}
}
int main()
{
char chars [89]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','~','!','@','#',
'$','%','^','&','*','(',')','_','+','=','?',';',':',',','<','>','{','}','[',']','\\','/','-'};
vector<string> start;
vector<string> stop;
string str("00");
string str2("89");
for (int i = 1; i<6; i++)
{
Tokenize(str, start);
Tokenize(str2, stop);
int length=start.size();
int depth = i;
generatePasswords(depth-1, chars,"", start, stop);
cout<<i<<" "<<clock()<<endl;
str=str+"-00";
str2=str2+"-89";
}
}
any ideas why my i7 powered osx machine is being so severely whipped by my core 2 duo linux machine?
thanks,
Mike