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

  • SEARCH
  • Home
  • 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 6682865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:45:19+00:00 2026-05-26T04:45:19+00:00

I am creating an app which mainly relies on timer, when the timer ticks

  • 0

I am creating an app which mainly relies on timer,

when the timer ticks my app will do a huge task;(my task manager says 50%, in a dual core machine,one core is fully used) .
It is creating two objects and 17 variables on an event.

How can i improve the performance of my timer event ;below are my ideas ,please clarify me whether it will improve or make worse

  1. creating and initializing local variables globally(declare them globally)
  2. concurrency // is it possible to do in delphi
  3. using a loop with sleep function instead of timer

and i need more idas from you to decrease the timer inteval as low as possible and keep the cpu usage as low as possible

The main reason for sluggishness is nested 4 loops ; but i have no any why to remove or reduce them

//======================== updated =================================================

Thanks for the response my app will monitor webcam and alert when a motion is detected ;
but sorry i cant post my code here;but i can tell u what is happening around the code

first the image will be broken in to 25*25 pieces ;2 loops for this

average color of a piece is stored retrived and compared with the current one ; 2 loops for this

then the app will show where the motion is detected

timer interval is currently set to 300

  • 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-05-26T04:45:19+00:00Added an answer on May 26, 2026 at 4:45 am

    Creating 2 class instances and 17 variables will just be done in no time – in much less time than the timer resolution is, in all cases.

    So there something else in your timer which burns your CPU. Data access, processing, calculation. It is impossible to guess what does need optimization without more information and source code.

    What you’ll need is to profile your application. You have AQTime in the latest versions of Delphi, but you may take a look at GPProfile or ProDelphi. You can use a profile-ready logging system like ours to make it on customer-side, if needed. Then you’ll see what is slow, i.e. where most of the time is spent.

    Using a loop with a sleep (in a background thread I guess) won’t be faster than a timer.

    IMHO what makes some repetitive task fast is using some pre-computed tables. There are perhaps some data that do not need to be computed or retrieved each time. So you may store those data in shared variables, and use it in the event handler. Always consider that changing an algorithm or avoiding data/hardware access is the key of speed. And always trust a profiler, not your first instinct.

    After updated question

    So your problem is directly related to process time of a picture. You still are in need of actual profiling to guess what shall be improved. I guess that you retrieve the picture in this timer. The process of a webcam picture won’t take 300 ms. So a possibility may be to use a background thread to retrieve the webcam images, push them in a round-robin list, then let the timer only process the latest image when asked for. But a real profiling of your code is needed.

    If the picture process itself in Delphi loops is the slow part, a sampling profiler will help you see which line of code needs speed up. Some advices in this case:

    • Try to use local variables within each loop to avoid re-computing of indexes (using pointers) or values (store them in the stack) in nested loops;
    • Try to access memory not randomly, but block per block (for better cache performance);
    • Align your data on 4 or 8 bytes alignment;
    • Unroll the inner loops (this may be a major speep up on modern CPUs) – e.g. if you merge some pixels blocks, hardwire the block reading and computing in your code, instead of using a for x := xRef-3 to xRef+3 do.. – main rule is to avoid any branch in your code – the less if ... then or for ... to appear in your code, the better;
    • Consider adding asm SSE/SSE2 instructions instead of pascal code (difficult part but also the more powerful), or use a third-party optimized library for your processing – there are several motion detection libraries around.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an app which will have a question in a UILabel and
Im creating an app in which i do a task when i receive a
I am creating an app which will be used to upload images to a
I am Creating an app which will store data of songs in database, i
I am creating an app which uses Core Data. I have a flip-side in
I'm planning on creating an app which will utilise Phonegap, however the app is
I am creating a iPod app which will on multiple devices. For each user
I am creating a rails app which will help out businesses. These businesses have
I have started creating an app which uses a core data stack at the
I am creating a web app which uses jQuery to authenticate: $.ajax({ url: /session/create?format=json,

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.