On 07/25/2007 06:46 AM, [email protected] wrote:
you could make a synthetic test by writing a memory hog that allocates
3/4 of your ram then pauses waiting for input and then randomly accesses
the memory for a while (say randomly accessing 2x # of pages allocated)
and then pausing again before repeating
Something like this?
run two of these, alternating which one is running at any one time. time
how long it takes to do the random accesses.
the difference in this time should be a fair example of how much it
would impact the user.
Notenotenote, not sure what you're going to show with it (times are simply
as horrendous as I'd expect) but thought I'd try to inject something other
than steaming cups of 4-letter beverages.
Rene.
/* gcc -W -Wall -o hog hog.c */
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
int main(void)
{
int pages, pagesize, i;
unsigned char *mem;
struct timeval tv;
pages = sysconf(_SC_PHYS_PAGES);
if (pages < 0) {
perror("_SC_PHYS_PAGES");
return EXIT_FAILURE;
}
pages = (3 * pages) / 4;
pagesize = sysconf(_SC_PAGESIZE);
if (pagesize < 0) {
perror("_SC_PAGESIZE");
return EXIT_FAILURE;
}
mem = malloc(pages * pagesize);
if (!mem) {
fprintf(stderr, "out of memory\n");
return EXIT_FAILURE;
}
for (i = 0; i < pages; i++)
mem[i * pagesize] = 0;
gettimeofday(&tv, NULL);
srand((unsigned int)tv.tv_sec);
while (1) {
struct timeval start;
getchar();
gettimeofday(&start, NULL);
for (i = 0; i < 2 * pages; i++)
mem[(rand() / (RAND_MAX / pages + 1)) * pagesize] = 0;
gettimeofday(&tv, NULL);
timersub(&tv, &start, &tv);
printf("%lu.%lu\n", tv.tv_sec, tv.tv_usec);
}
return EXIT_SUCCESS;
}
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]