From: Brian Candler Date: 2008-09-16T23:42:13+09:00 Subject: Re: Optimization help - reading out of /proc on Solaris > 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. struct = ProcTableStruct.new(*psinfo.unpack(<