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 9246227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:26:47+00:00 2026-06-18T09:26:47+00:00

I’m using celluloid’s every method to execute a block every microsecond however it seems

  • 0

I’m using celluloid’s every method to execute a block every microsecond however it seems to always call the block every second even when I specify a decimal.

interval = 1.0 / 2.0

every interval do
  puts "*"*80
  puts "Time: #{Time.now}"
  puts "*"*80
end

I would expect this to be called every 0.5 seconds. But it is called every one second.

Any suggestions?

  • 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-18T09:26:48+00:00Added an answer on June 18, 2026 at 9:26 am

    You can get fractional second resolution with Celluloid.

    Celluloid uses the Timers gem to manage the every, which does good floating point time math and ruby’s sleep which has reasonable sub-second resolution.

    The following code works perfectly:

    class Bob
      include Celluloid
      def fred
        every 0.5 do
          puts Time.now.strftime "%M:%S.%N"
        end
      end
    end
    
    Bob.new.fred
    

    And it produces the following output:

    22:51.299923000
    22:51.801311000
    22:52.302229000
    22:52.803512000
    22:53.304800000
    22:53.805759000
    22:54.307003000
    22:54.808279000
    22:55.309358000
    22:55.810017000
    

    As you can see, it is not perfect, but close enough for most purposes.

    If you are seeing different results, it is likely because of how long your code takes in the block you have given to every or other timers running and starving that particular one. I would approach it by simplifying the situation as much as possible and slowly adding parts back in to determine where the slowdown is occurring.

    As for microsecond resolution, I don’t think you can hope to get that far down reliably with any non-trivial code.

    The trivial example:

    def bob
      puts Time.now.strftime "%M:%S.%N"
      sleep 1.0e-6
      puts Time.now.strftime "%M:%S.%N"
    end
    

    Produces:

    31:07.373858000
    31:07.373936000
    
    
    31:08.430110000
    31:08.430183000
    
    
    31:09.062000000
    31:09.062079000
    
    
    31:09.638078000
    31:09.638156000
    

    So as you can see, even just a base ruby version on my machine running nothing but a simple IO line doesn’t reliably give me microsecond speeds.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.