guys:

i am doing a benchmark on java memory management. i wrote an app to allocate
and free memory from 1 to 300k bytes. it runs forever. i notice it takes
longer to allocate additional memory as time goes on. the same app only
takes 9 seconds on C++. here's the code listing. can anyone pls help out?

tks,
peter

=======JAVA CODE LISTING =======
public class Class1
{
 private static final int NUM_MAX_BYTES = 300000;

 public static void main (String[] args)
 {
  int i;
  long t1;

  t1 = System.currentTimeMillis();

  System.err.print("memory alloc/free 1 - "+NUM_MAX_BYTES+" bytes. ");
  for (i = 0; i < NUM_MAX_BYTES; i++)
  {
   byte[] p;
   p = new byte[i];
   if (i % 1000 == 0)
   {
    // Runtime rt = Runtime.getRuntime();
    // rt.gc();
    System.err.println("current: "+i);
   }
  }

  System.err.println("time taken: %d "+ (System.currentTimeMillis()-t1) +
"ms");

 }
}


======= C++ CODE LISTING =========

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>

#define NUM_MAX_BYTES 300000

int main(int argc, char* argv[])
{
 int i;
 DWORD t1;
 t1 = GetTickCount();

 BYTE * p;
 printf("memory alloc/free 1 - %d bytes. ", NUM_MAX_BYTES);
 for (i = 0; i < NUM_MAX_BYTES; i++)
 {
  p = new BYTE[i];
  delete p;
 }
 printf("time taken: %d ms\n",GetTickCount()-t1);

 return 0;
}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to