# Find out the time used for searching a file

**URL:** <https://www.ruby-forum.com/t/find-out-the-time-used-for-searching-a-file/73237>\
**Category:** Ruby\
**Created:** [October 23, 2006, 4:46am UTC](https://www.ruby-forum.com/t/find-out-the-time-used-for-searching-a-file/73237 "2006-10-23T04:46:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 23, 2006, 4:46am UTC](https://www.ruby-forum.com/t/find-out-the-time-used-for-searching-a-file/73237/1 "2006-10-23T04:46:41Z")

</div>

Hi all,

When I run a script to search some files in a folder and/or its children  
folders I want know how long it takes when the search is done. Is there  
any such method available in Ruby ?

Thanks,

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 23, 2006, 7:26am UTC](https://www.ruby-forum.com/t/find-out-the-time-used-for-searching-a-file/73237/2 "2006-10-23T07:26:46Z")

</div>

Li Chen wrote:

> When I run a script to search some files in a folder and/or its children  
> folders I want know how long it takes when the search is done. Is there  
> any such method available in Ruby ?

a) Research the Benchmark library  
b)  
start\_time = Time.new

# do stuff here

end\_time = Time.new  
puts( “It took #{end\_time - start\_time} seconds” )

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 23, 2006, 8:00am UTC](https://www.ruby-forum.com/t/find-out-the-time-used-for-searching-a-file/73237/3 "2006-10-23T08:00:49Z")

</div>

require ‘benchmark’

seconds = Benchmark.realtime do  
#do stuff here  
end
