Re: [netcdfgroup] strlen calls in NC_finddim and NC_findvar

  • To: "Ed Hartnett" <ed@xxxxxxxxxxxxxxxx>
  • Subject: Re: [netcdfgroup] strlen calls in NC_finddim and NC_findvar
  • From: "Greg Sjaardema" <gdsjaar@xxxxxxxxxx>
  • Date: Thu, 3 Dec 2009 22:18:40 -0700
Ed Hartnett wrote:
> "Greg Sjaardema" <gdsjaar@xxxxxxxxxx> writes:
> 
>> I have a monstrous file with several thousand dimensions and variables
>> which is running slower than it should.  I investigated the runtime
>> and found that strlen was the major time user in the NC_finddim and
>> NC_findvar calls.  The obvious optimization was to cache the length of
>> the name instead of calling strlen each time.  However, when I went to
>> do this, I discovered that the length is already cached as the nchars
>> field in the NC_string struct.
>>
>> I did some checks in the code and also added some assertions to the
>> code and verified that, as far as I can tell, nchars is the correct
>> length of the string.  Is there a reason that it isn't used and
>> strlen() is called instead?  Switching the code to use nchars dropped
>> my execution time from 20 units to 6 units.  I would like to make the
>> switch, but wondered if there was some strange corner case where the
>> nchars value is incorrect and will cause problems.
>>
>> Thanks,
>> --Greg
>>
> 
> Howdy Greg!
> 
> Sounds interesting!
> 
> Can you send your patch to support-netcdf@xxxxxxxxxxxxxxxx and we can
> take a look?
> 
> Thanks,
> 
> Ed
> 
Actually, I didn't look close enough.  The NC_string nchars actually
isn't always the length of the string.  I have an alternative way to do
this which I will send tomorrow, but I'm not sure it will be worth it
for "normal-sized" files.

--Greg



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