Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 2002 11:25:43 +0200
From:      Danny Braniss <danny@cs.huji.ac.il>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   malloc
Message-ID:  <E183Yoh-0009TR-00@cse.cs.huji.ac.il>

next in thread | raw e-mail | index | archive | help
the attached program - which shows the 'efficiancy' of our scientific
programmers - tickled my curiosity.

if compiled under Linux, it would run fine on FreeBSD 4.7-stable.
compiled on FreeBSD it would bomb.

so i fixed some kernel values (options 	MAXDSIZ="(2*1024*1024*1024)")
and it run to complition, but:
fbsd compiled: complex-2 took 23.652872 seconds, mem used=800000000(762M)
linux        : complex-2 took 11.969896 seconds, mem used=800000000(762M)


comments?

	danny

#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>

int MAX_N, mem;

int main(int argc , char ** argv){
     int	i;
     int	** arr;
     struct timeval t1, t2;

     if(argc > 1)
	  MAX_N = atoi(argv[1]);
     else
	  MAX_N = 100000000;

     gettimeofday(&t1, 0);
     mem = sizeof (int *) * MAX_N;
     arr = malloc(mem);
     if(arr == NULL) {
	  perror("Malloc");
	  exit(1);
     }
     for (i = 0 ; i < MAX_N ; ++i ){
	  arr[i]  = malloc(sizeof(int));
	  if(arr[i] == NULL) {
	       perror("malloc2");
	       printf("failed at %d, mem=%d(%d)\n", i, mem, mem/(1024 * 1024));
	       exit(1);
	  }
	  *arr[i] = i;
	  mem += sizeof(int);
     }
     gettimeofday(&t2, 0);
     printf ("%s took %f seconds, mem used=%d(%dM)\n",
	     getenv ("HOST"),
	     t2.tv_sec-t1.tv_sec + (t2.tv_usec-t1.tv_usec)/(float)(1000000),
	     mem, mem / (1024 * 1024));


     for (i = 0 ; i < MAX_N ; ++i ){
	  if(*arr[i] != i)
	       printf("GUEVALT! %d] %d\n", i, *arr[i]);
     }
     exit(0);
}



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E183Yoh-0009TR-00>