Skip to content

Instantly share code, notes, and snippets.

@TakashiHarada
Created August 25, 2015 02:12
Show Gist options
  • Save TakashiHarada/8a90508177d2bd852e80 to your computer and use it in GitHub Desktop.
Save TakashiHarada/8a90508177d2bd852e80 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX_STRING 128
int takeuti(unsigned long x, unsigned long y, unsigned long z)
{
if (x <= y) {
return z;
}
return takeuti(takeuti(x-1, y, z), takeuti(y-1, z, x), takeuti(z-1, x, y));
}
void use_system(void)
{
char command[MAX_STRING];
sprintf(command, "grep VmHWM /proc/%d/status", getpid());
system(command);
}
void f(vector<int> *v, int n)
{
for (int i = 0; i < n; ++i)
{
v->push_back(i);
}
}
int main()
{
vector<int> *v = new vector<int>;
struct rusage usage0;
struct rusage usage1;
getrusage(RUSAGE_SELF, &usage0);
f(v, 1000000);
getrusage(RUSAGE_SELF, &usage1);
printf("%ld\n", getpagesize());
//printf("%ld\n", usage0.ru_ixrss);
printf("%ld\n", usage1.ru_maxrss);
//printf("%ld\n", usage1.ru_ixrss);
//if (usage1.ru_utime.tv_usec < usage0.ru_utime.tv_usec) {
// printf("%d.%d\n", usage1.ru_utime.tv_sec - usage0.ru_utime.tv_sec - 1, 1000000 + usage1.ru_utime.tv_usec - usage0.ru_utime.tv_usec);
//}
//else {
// printf("%d.%d\n", usage1.ru_utime.tv_sec - usage0.ru_utime.tv_sec, usage1.ru_utime.tv_usec - usage0.ru_utime.tv_usec);
//}
free(v);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment