[ create a new paste ] login | about

Link: http://codepad.org/26jVqmW3    [ raw code | output | fork ]

C++, pasted on Sep 14:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

#define ITER 1000000

struct foo1 {
  __int64 start, end, freq; 

  HANDLE hprocess; 
  DWORD oldclass; 

  foo1() : hprocess(GetCurrentProcess()),  oldclass(GetPriorityClass(hprocess)) {
    Sleep(10); 
//    SetPriorityClass(hprocess, REALTIME_PRIORITY_CLASS); 
    QueryPerformanceFrequency((LARGE_INTEGER*)&freq); 
    QueryPerformanceCounter((LARGE_INTEGER*)&start); 
  }
  ~foo1() {
    QueryPerformanceCounter((LARGE_INTEGER*)&end); 
//    SetPriorityClass(hprocess, oldclass); 
    std::cout << (int)(end - start) << std::endl;
  }
};

struct person {
  int age;
  string name;

  person(int age, const string& name) : age(age), name(name) {}
};

void foo(const person&& x)
{
  // cout << "rvalue : " << x.age << "," << x.name << endl;
}

void foo(const person& x)
{
  // cout << "lvalue : " << x.age << "," << x.name << endl;
}

int main()
{
  {
    foo1 f;
    for (int i = 0; i < ITER; i++)
      foo(person(22, "Akira")); // rvalue : 22,akira
  }
  
  person johnny(38, "Johnny");
  
  {
    foo1 f;
    for (int i = 0; i < ITER; i++)
      foo(johnny); // lvalue : 38,Johnny
  }
}


Output:
1
2
3
Line 20: error: windows.h: No such file or directory
Line 9: error: '__int64' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: