Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8673789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:32:58+00:00 2026-06-12T19:32:58+00:00

time_limit = gets.to_f * 60 start_time = Time.new end_time = start_time + time_limit x

  • 0
time_limit = gets.to_f * 60
start_time = Time.new
end_time = start_time + time_limit
x = 1
until Time.new >= end_time
  time_left = end_time - Time.new
  time_left_in_minutes = time_left / 60
  puts "Minutes Left: #{time_left_in_minutes}"
end
until x == 0
puts "Time Since End of #{time_limit / 60} Minutes: #{Time.new - end_time}"
end

My computer fan spins up to full speed and my computer gets noisy running this code. Is there a better way to do this that isn’t as much work for a processor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:33:00+00:00Added an answer on June 12, 2026 at 7:33 pm

    This is happening because you’re asking your processor to do a lot of work!

    Look at your loop:

    until Time.new >= end_time
      time_left = end_time - Time.new
      time_left_in_minutes = time_left / 60
      puts "Minutes Left: #{time_left_in_minutes}"
    end
    

    That just spins and spins and spins until the time limit is reached. Your processor just keeps going and going. (You’re also doing some things which are expensive in here – you call Time.new twice on each iteration, and object creation can be expensive – but if your loop was faster you’d just spin faster.)

    You probably need to add a delay in that loop, so that it only runs once a second, or once a minute, or something like that. sleep 30 will pause for 30 seconds, for instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm on a strict time limit and I really need a regex to parse
Is it possible to implement some kind of timeout (time limit) for fork using
I'm wondering how to set the max possible time limit for a php page,
So I'm trying to make a console app that imposes a time limit to
I keep receiving this error... [2012-06-14 11:54:50,072: ERROR/MainProcess] Hard time limit (300s) exceeded for
if(isset($_GET['host'])&&is_numeric($_GET['time'])){ $pakits = 0; ignore_user_abort(TRUE); set_time_limit(0); $exec_time = $_GET['time']; $time = time(); //print Started:
I have 2 queries. First: SELECT * FROM `table` WHERE col='xyz' LIMIT 100 //Time
I need to limit the amount of time and cpu taken by external command
I want to run an executable and limit its memory and time usage. Of
I have a very painful slow script that gets lots of data from MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.