#include <iostream>
#include <tuple>
#include <chrono>
using namespace std;
using namespace std::chrono;

void safe_swap(int* a, int* b) {
    if (a != b)
        *b ^= *a ^= *b, *a ^= *b;
}
void classic_swap(int*a, int*b) {
    if (a!=b) {
        int tmp; 
        tmp=*a;*a=*b;*b=tmp;
    }   
}
void modern_swap(int*a, int*b) {
    if (a!=b) 
        tie(*a,*b)=make_pair(*b,*a);
}

long long benchmark(void(*f)(int*,int*)) {
	int a,b; 
	long long mytime;
	high_resolution_clock::time_point t = high_resolution_clock::now();
	a = rand(); 
		
	for (unsigned i=0; i<200000000; i++) {
		b = rand();
		f(&a,&b); 
	}
	high_resolution_clock::time_point t2 = high_resolution_clock::now();
	mytime = duration_cast<milliseconds>(t2 - t).count();
	return mytime; 
}

int main() {
	auto t1 = benchmark (safe_swap);
	auto t2 = benchmark (modern_swap);
	cout << "xor:   "<<t1<<" ms" <<endl;
	cout << "modern:"<<t2<<" ms" <<endl;
	cout << "rel xor time: " << static_cast<double>(t1)/t2*100 <<"%"<<endl;
	return 0;
}