View Single Post
Old 07-10-12, 09:49 AM   #17
KDE
Registered User
 
Join Date: Nov 2007
Posts: 50
Default Re: Support for X32 ABI

Benchmark x86 vs x86-64 vs X32

Elapsed time:
X32 - 33014 ms - 100%
x86-64 - 37505 ms - 114%
x86 - 38655 ms - 117%

Memory usage:
X32 - 41884 kB - 100%
x86 - 42096 kB - 101%
x86-64 - 58636 kB - 140%

Code:
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sched.h>
#include <errno.h>
#include <iostream>
#include <fstream>
#include <set>
#include <string>

using namespace std;
int main(int argc, char *argv[])
{
    cpu_set_t cpuset;
    CPU_ZERO(&cpuset);
    CPU_SET(0, &cpuset);
    if (sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset)) {
        cout << "errno1: " << errno << endl;
    }
    set<long long int> set1;
    timespec start, end;
    ifstream numberFile("numbers");
    long long int* numbers = new long long int[1024 * 1024];
    long long int sum = 0;
    if (numberFile.good()) {
        numberFile.read((char*)numbers, 8 * 1024 * 1024);
        for (int i = 0; i < 1024 * 1024; i++) {
            sum += numbers[i];
        }
        cout << "sum1: " << sum << endl;
    } else {
        ofstream numberFile2("numbers");
        for (int i = 0; i < 1024 * 1024; i++) {
            sum += (numbers[i] = random());
        }
        cout << "sum2: " << sum << endl;
        numberFile2.write((char*)numbers, 8 * 1024 * 1024);
    }
    sync();
    clock_gettime(CLOCK_REALTIME, &start);
    sum = 0;
    for(int i=0;i<32;i++) {
        int count = 1024 * 1024;
        long long int* it = numbers;
        while (count--) {
            set1.insert(*it++);
        }
        for(auto it = set1.begin();it != set1.end(); it++) {
            sum += *it;
        }
        set1.clear();
    }
    cout << "sum3: " << sum << endl;
    clock_gettime(CLOCK_REALTIME, &end);
    long long int i1 = (end.tv_sec - start.tv_sec);
    i1 *= 1000000000;
    long long int i2 = (end.tv_nsec- start.tv_nsec);
    cout << "Elapsed time: " << (i1 + i2) / 1000000 << " ms" << endl;
    ifstream statusFile("/proc/self/status");
    string line;
    while (statusFile.good()) {
        getline(statusFile, line);
        if (line.find("VmRSS") != string::npos) {
            cout << "Memory usage: " <<  line << endl;
        }
    }
    set1.clear();
}
KDE is offline   Reply With Quote