From: Steve Tuckner Date: 2001-12-21T06:24:32+09:00 Subject: [ruby-talk:29171] Dir and Stat on windows This is a multi-part message in MIME format. ------=_NextPart_000_0023_01C1896A.61A86890 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I want to do a task where I get an array of all files in a directory that have a modification date later than a certain time/date. The directory that I often work in has 3300 files in it and so the following code takes 1:25 seconds to run. require "profile" files = Dir["RX*.fax"] fileinfo = {} files.each do |file| fileinfo[file] = File.stat(file).mtime end print "# of files = #{files.size}\n" The profile output makes no sense to me because the cumulative times do not match what I saw # of files = 1365 % cumulative self self total time seconds seconds calls ms/call ms/call name 49.73 0.93 0.93 1 931.00 1852.00 Array#each 31.04 1.51 0.58 1365 0.43 0.43 File#stat 9.62 1.69 0.18 1365 0.13 0.13 Hash#[]= 8.55 1.85 0.16 1365 0.12 0.12 File::Stat#mtime 1.07 1.87 0.02 1 20.00 20.00 Dir#[] 0.00 1.87 0.00 1 0.00 0.00 Fixnum#to_s 0.00 1.87 0.00 1 0.00 0.00 Kernel.print 0.00 1.87 0.00 1 0.00 0.00 IO#write 0.00 1.87 0.00 1 0.00 0.00 Array#length 0.00 1.87 0.00 1 0.00 1872.00 #toplevel Any idea on why the profile output looks goofy or on how to speed up this operation? Steve Tuckner ------=_NextPart_000_0023_01C1896A.61A86890 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I = want to do a task=20 where I get an array of all files in a directory that have a = modification date=20 later than a certain time/date. The directory that I often work in has = 3300=20 files in it and so the following code takes 1:25 seconds to=20 run.
 
require=20 "profile"
 
files = =3D=20 Dir["RX*.fax"]
fileinfo =3D {}
files.each do = |file|
 fileinfo[file]=20 =3D File.stat(file).mtime
end
print "# of files =3D=20 #{files.size}\n"
The = profile output=20 makes no sense to me because the cumulative times do not match what I=20 saw
 
# of = files =3D=20 1365
  %   cumulative  =20 self           &n= bsp; =20 self     total
 time   = seconds  =20 seconds    calls  ms/call  ms/call =20 name
 49.73     = 0.93     =20 0.93        1   = 931.00 =20 1852.00  Array#each
 31.04    =20 1.51      0.58    =20 1365     0.43     0.43 =20 File#stat
  9.62    =20 1.69      0.18    =20 1365     0.13     0.13 =20 Hash#[]=3D
  8.55    =20 1.85      0.16    =20 1365     0.12     0.12 =20 File::Stat#mtime
  1.07    =20 1.87     =20 0.02        1   =20 20.00    20.00  Dir#[]
 =20 0.00     1.87     =20 0.00        = 1    =20 0.00     0.00  Fixnum#to_s
 =20 0.00     1.87     =20 0.00        = 1    =20 0.00     0.00  Kernel.print
 =20 0.00     1.87     =20 0.00        = 1    =20 0.00     0.00  IO#write
 =20 0.00     1.87     =20 0.00        = 1    =20 0.00     0.00  Array#length
 =20 0.00     1.87     =20 0.00        = 1    =20 0.00  1872.00  #toplevel
Any = idea on why the=20 profile output looks goofy or on how to speed up this=20 operation?
 
Steve = Tuckner
------=_NextPart_000_0023_01C1896A.61A86890--