Author Topic: Difference in CPU Usage in Hardware vs Software images  (Read 2874 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Difference in CPU Usage in Hardware vs Software images
« on: January 26, 2021, 04:38:49 pm »
I'm back home, and had a little time today to play around with the PC for a bit, so I thought I'd take a quick moment to write up a simple little demo of how and why folks might want to make use of hardware images.  We really don't see them made use of in programs much, and it's honestly a shame, as you can see from below:

Code: QB64: [Select]
  1. x = 18
  2.     LINE (x, 0)-STEP(14, _HEIGHT), &H2CFFFFFF, BF
  3.     LINE (x + 1, 0)-STEP(12, _HEIGHT), &H83FFFFFF, BF
  4.     LINE (x + 3, 0)-STEP(8, _HEIGHT), &H03FFFFFF, BF
  5.     x = x + 32
  6. y = 18
  7.     LINE (0, y)-STEP(_WIDTH, 14), &H2CFFFFFF, BF
  8.     LINE (0, y + 1)-STEP(_WIDTH, 12), &H83FFFFFF, BF
  9.     LINE (0, y + 3)-STEP(_WIDTH, 8), &H03FFFFFF, BF
  10.     y = y + 32
  11. CI = _COPYIMAGE(0)
  12. 'CI = _COPYIMAGE(0, 33)
  13. x = 0: y = 0
  14. l = 300
  15.     CLS
  16.     _PUTIMAGE (x, y), CI
  17.     IF x < 0 THEN _PUTIMAGE (_WIDTH + x, y), CI, 0, (0, 0)-(-x, _HEIGHT)
  18.     IF y < 0 THEN _PUTIMAGE (x, _HEIGHT + y), CI, 0, (0, 0)-(_WIDTH, -y)
  19.     IF x < 0 AND y < 0 THEN _PUTIMAGE (_WIDTH + x, _HEIGHT + y), CI, 0, (0, 0)-(-x, -y)
  20.     IF x < -_WIDTH THEN x = 0
  21.     IF y < -_HEIGHT THEN y = 0
  22.     change = INT(RND * 2)
  23.     IF change THEN x = x - 1 ELSE y = y - 1
  24.     IF ABS(TIMER - INT(TIMER)) < .1 THEN l = INT(RND * 300) + 30
  25.     _LIMIT l
  26.     _DISPLAY

Now this is nothing more than a simple little screen pattern which we scroll diagonally up and left across the screen.  To start with, we run it in normal, software graphical mode, so you guys can pop open task manager and look at the CPU usage of our program.

Let it run for a bit and watch the CPU usage -- I've got a variable limit in here (you can tell by how fast the screen scrolls), so you can get a range of how much processing power your machine does on it with limits somewhere between 30 and 330.

On my PC, task manager tells me it's using from 8 to 14% CPU power -- which is enough to crank my fans up on my PC and make them sound like an airplane engine starting up!



And then, we go into the IDE and unremark out the line with the COPYIMAGE in it, and we remark the line below it:

'CI = _COPYIMAGE(0)
CI = _COPYIMAGE(0, 33)

This says we're now going to be using a hardware image for our main program.  Once again, at this point, compile, run and watch the results for about a minute or so.  There's no RANDOMIZER TIMER in this, so we're going to be getting the *exact* same LIMITs as what we had last time...

... And yet, all we're seeing here is from 0.8 to 2.1% CPU usage!!

Exact same program, with only one small change -- hardware over software images -- and yet it now has almost no effect on CPU usage.  My fans never crank on.  My airplane stays parked in my chassis, and life is GOOD!!



And here's to hoping that we'll be seeing more folks asking questions and playing around with hardware images in the future.  *Cheers!*
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Difference in CPU Usage in Hardware vs Software images
« Reply #1 on: January 26, 2021, 04:55:12 pm »
We interrupt this message to bring you these hot deals from ebay...

Buy it Now: Used QB64 laptops, with QB64 Version prior to _LIMIT and hardware image abilities installed! Laptop has many features and comes complete with built in smoke detector.



Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Difference in CPU Usage in Hardware vs Software images
« Reply #2 on: January 27, 2021, 05:09:13 pm »
conceptually, what is the difference between hardware and software images?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Difference in CPU Usage in Hardware vs Software images
« Reply #3 on: January 27, 2021, 05:10:45 pm »
conceptually, what is the difference between hardware and software images?

Hardware images process on your GPU.  Software images on your CPU.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Difference in CPU Usage in Hardware vs Software images
« Reply #4 on: January 27, 2021, 05:17:10 pm »
ok, I got it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Difference in CPU Usage in Hardware vs Software images
« Reply #5 on: January 27, 2021, 06:22:55 pm »
Thanks I did not know that about CPU usage, though I don't use _COPYIMAGE, the only other place is _LOADIMAGE?

So by default we should use Hardware images unless... what?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Difference in CPU Usage in Hardware vs Software images
« Reply #6 on: January 27, 2021, 06:34:00 pm »
So by default we should use Hardware images unless... what?

Unless you need to be altering them constantly.  We can't access hardware images directly, so we draw and build a software image, and then display the hardware images.

But, they can also be used to do things such as this hybrid graphic-text screen:
Code: QB64: [Select]
  1. LOCATE 1, 1
  2. PRINT "Hello World"
  3.  
  4.  
  5. temp = _NEWIMAGE(200, 200, 32)
  6. _DEST temp
  7. CIRCLE (100, 100), 75, _RGB32(255, 255, 0)
  8. PAINT (100, 100), _RGB32(255, 255, 0)
  9. temp_hw = _COPYIMAGE(temp, 33)
  10.  
  11.     _LIMIT 10
  12.     _PUTIMAGE (100, 100), temp_hw
  13.     _DISPLAY
  14.  
  15. PRINT "One thing to notice about hardware images --"
  16. PRINT "they're completely seperate from our software screens,"
  17. PRINT "which means we can use them even with SCREEN 0!"
  18.  


https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!