I'm writing simple program and I want to mesure time of its execution on Windows and Linux (both 64). I have a problem, because for 1 000 000 elements in table on Windows it takes about 35 seconds, while on linux it takes about 30 seconds for 10 elements. Why the difference is so huge? What am I doing wrong? Is there something in my code that is not proper on Linux?
Here is my code:
void fillTable(int s, int t[])
{
srand(time(0));
for (int i = 0; i < s; i++)
{
t[i] = rand();
}
}
void checkIfIsPrimeNotParalleled(int size, int table[])
{
for (int i = 0; i < size; i++)
{
int tmp = table[i];
if (tmp < 2)
{
}
for (int i = 2; i < tmp; i++)
{
if (tmp % i == 0)
{
}
else
{
}
}
}
}
void mesureTime(int size, int table[], int numberOfRepetitions)
{
long long sum = 0;
clock_t start_time, end_time;
fillTable(size, table);
for (int i = 0; i < numberOfRepetitions; i++)
{
start_time = clock();
checkIfIsPrimeNotParalleled(size, table);
end_time = clock();
double duration = (end_time - start_time) / CLOCKS_PER_SEC;
sum += duration;
}
cout << "Avg: " << round(sum / numberOfRepetitions) << " s"<<endl;
}
int main()
{
static constexpr int size = 1000000;
int *table = new int[size];
int numberOfRepetitions = 1;
mesureTime(size, table, numberOfRepetitions);
delete[] table;
return 0;
}
and the makefile for Linux. On Windows I'm using Visual Studio 2015
.PHONY: Project1
CXX = g++
EXEC = tablut
LDFLAGS = -fopenmp
CXXFLAGS = -std=c++11 -Wall -Wextra -fopenmp -m64
SRC= Project1.cpp
OBJ= $(SRC:.cpp=.o)
all: $(EXEC)
tablut: $(OBJ)
$(CXX) -o tablut $(OBJ) $(LDFLAGS)
%.o: %.cpp
$(CXX) -o $@ -c $< $(CXXFLAGS)
clean:
rm -rf *.o
mrproper: clean
rm -rf tablut
The main goal is to mesure time.