From: Ken Bloom Date: 2008-09-19T07:47:22+09:00 Subject: Re: Optimization help - reading out of /proc on Solaris Brian Candler wrote: >> Anyway, below is the code. I ran it through the profiler, but the top >> two most costly ops were Dir.foreach, which I don't see any way to >> optimize*, and the loop that gathers environment information, which I >> again see no way to optimize. > > Could you post your profiling? If you run using "time", how much user > CPU versus system CPU are you using? > > Have you tried using Dir.open.each instead of Dir["/foo/*"]? Maybe > globbing is expensive. > > Your environment loop does a fresh sysread(1024) for each var=val pair, > even if you've only consumed (say) 7 bytes from the previous call. You > would make many fewer system calls if you read a big chunk and chopped > it up afterwards. This may also avoid non-byte-aligned reads. > > I would also be tempted to write one long unpack instead of lots of > string slicing and unpacking. The overhead here may be negligible, but > the code may end up being smaller and simpler. e.g. Method calls are expensive. Right now he's got 3 per field (array indexing, unpack, and assignment). He could get that down to 1 per field (assignment only) pretty easily by following your suggestion. -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/