Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.

[netcdf-java] performance issue

Hi,
I'm using java NetCDF 2.2.20. One of the issues which I have related to very 
low performance comparing to .Net wrapper on "C" library 3.6.1
For instance I made simple straight forward test case:

-          Create a file

-          1 dimension

-          1 variable type Float

-          Dump values as arrays of 5 elements


Java code:
             try {
             NetcdfFileWriteable ncFile = 
NetcdfFileWriteable.createNew("d:\\duck2.nc", false);
            Dimension timeDim = ncFile.addDimension(timeSeriesDimensionName, 
-1, true, true, false);
            Dimension[] dim1 = new Dimension[1];
            dim1[0] = timeDim;
          ncFile.addVariable("avar", DataType.FLOAT, dim1);
          ncFile.create();
          int c=0;
            float[] arr;
            arr=new float[5];
            arr[0]=50;
            arr[1]=40;
            arr[2]=30;
            arr[3]=20;
            arr[4]=10;
            int i, j;
            for(j=0;j<2000;j++)
            for(i=0;i<50000;i++){
                  int[] timeOrigin = new int[] {c};
                  ncFile.write("avar", timeOrigin, Array.factory(arr));
                  c+=5;

            }
            ncFile.flush();
            ncFile.close();
            }
             catch(Exception ex){

             }


And similar VB.NET code

        Dim ncid As Integer
        Dim dimid As Integer
        Dim varid As Integer

        Dim v(4) As Single
        v(1) = 10
        v(2) = 20
        v(3) = 30
        v(4) = 40
        v(0) = 50
        Dim vSize(0) As Integer
        vSize(0) = 5

        Dim res As Integer
        Dim dims(0) As Integer

        res = NetCDF.nc_create("d:\duck.nc", NetCDF.cmode.NC_WRITE, ncid)
        res = NetCDF.nc_def_dim(ncid, "big_dim", 0, dimid)
        dims(0) = dimid
        res = NetCDF.nc_def_var(ncid, "big_var", NetCDF.nc_type.NC_FLOAT, 1, 
dims, varid)
        NetCDF.nc_enddef(ncid)

        Dim idx(0) As Integer
        Dim i As Integer
        Dim j As Integer

        idx(0) = 0
        For j = 0 To 2000
            For i = 0 To 50000
                res = NetCDF.nc_put_vara_float(ncid, varid, idx, vSize, v)
                idx(0) = idx(0) + vSize(0)

            Next
        Next

***************************


Java code is approximately 40 times slower.
Apparently, making a bigger buffer (for instance arrays of 10000 instead of 5 
elements) in Java case will reduce the difference, but anyway it very 
significant.
Any suggestion how to improve it?

Thanks,
Mark Balonkin

  • 2008 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: