![]() |
|
[Python] Counting - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Counting (/showthread.php?tid=5600743) Pages: Pages
1
2
|
Counting - systx - Apr 15, 2017 I want to create a program that will count to a super high number I have tried the following... PHP Code I have also tried... PHP Code It's like only have one threading running though So any tips on how to do this would be AWSOME!!! 🤩 * - Woes - Apr 15, 2017 (Apr 15, 2017 07:46 PM)systx Wrote: I want to create a program that will count to a super high # Wait what?! Lmao. Code x=0* - Riԁdle - Apr 15, 2017 (Apr 15, 2017 07:46 PM)systx Wrote: I want to create a program that will count to a super high #just a bit confused.. if you're on 2.7 and you're lagging try PHP Code Code range(1,9999)PHP Code Code range(1, 200, 5) # counts by 5* - systx - Apr 15, 2017 (Apr 15, 2017 08:07 PM)Woes Wrote: Wait what?! Lmao. Lol sorry # = Number (Apr 15, 2017 09:19 PM)Ghosting12 Wrote: just a bit confused.. if you're on 2.7 and you're lagging try Yeah I'm using py 3.x Sadly I need to count up by 1. It needs to count up to 200000000000 sadly 😟 It would take a couple years to do with one thread :( * - Riԁdle - Apr 15, 2017 (Apr 15, 2017 09:26 PM)systx Wrote: Lol sorry # = Number may I ask why you need to count that? try this PHP Code * - obby - Apr 16, 2017 He is creating a list. (to person who said xrange(int) or range(int) wasnt a list) Secondly if you want to count to a higher humber just do xrange(999999999999) or something? Why all of that nonsense? I can't imagine threading, async or multi processing making this faster... But... Code from threading import Thread* - IWannaLearn144 - Apr 16, 2017 Using threading to make the program count faster is not very useful at all. Threading, in my opinion, is only really useful if you are doing a lot of file i/o and networking tasks like port scanning. Threading use to be more useful before python 3.2 because there were a few efficiency issues. There was a guy that done a whole talk on this but i cant remember his name. * - systx - Apr 16, 2017 (Apr 16, 2017 05:26 AM)obby Wrote: He is creating a list. (to person who said xrange(int) or range(int) wasnt a list) All the nonsense is so I can't count to a high number very quickly. For x in range(99999) is extremely slow as it only uses one thread. Also you don't need theInt globalized Thanks for the input 🤝 (Apr 15, 2017 10:43 PM)Ghosting12 Wrote: may I ask why you need to count that? Sadly your program doesn't share variables correctly :( I need it for a project of mine. * - Riԁdle - Apr 16, 2017 (Apr 16, 2017 10:01 AM)systx Wrote: All the nonsense is so I can't count to a high number very quickly. For x in range(99999) is extremely slow as it only uses one thread. Also you don't need theInt globalizedwym it doesnt share variables correctly? it works fine for me. maybe I don't understand what you mean, could you explain it * - TheWarOwl - Apr 16, 2017 Do you mean something like this? PHP Code * - systx - Apr 16, 2017 (Apr 16, 2017 01:02 PM)Piero-Bird Wrote: Do you mean something like this? I'm not sure. I'm a little confused as how it works. * - SIM-1866423 - Apr 17, 2017 Idk whatever you are trying to do but im pretty sure there has some better ways to do.Currently just seems like you are trying to do some useless loop, why? * - systx - Apr 17, 2017 (Apr 17, 2017 05:03 AM)Mnemosyne Wrote: Idk whatever you are trying to do but im pretty sure there has some better ways to do.Currently just seems like you are trying to do some useless loop, why? Yeah I think your right, I decided to go in a different direction that works just fine, anyways thanks guys. 🤝 * - obby - Apr 18, 2017 (Apr 16, 2017 10:01 AM)systx Wrote: All the nonsense is so I can't count to a high number very quickly. For x in range(99999) is extremely slow as it only uses one thread. Also you don't need theInt globalized just because you said im wrong i decided to actually run the code :) runs fine: Code from threading import Threadruns with exception: UnboundLocalError: local variable 'theInt' referenced before assignment Code from threading import ThreadThank you I'll take your apology in full. Also expanding on the topic: Counting to 4 billion! ---------------------------------------- Code root@DN16:~# cat omfg.py---------------------------------------- Fastest Code root@DN16:~# cat omfg2.py---------------------------------------- This ran for 3+ minutes I didnt bother letting it finish. This code came from: http://eli.thegreenplace.net/2012/01/04/shared-counter-with-pythons-multiprocessing Code root@DN16:~# cat omfg3.py---------------------------------------- Multiprocessing requires locking/releasing due to needing to be concurrent. However 4 processes counting to 1 million without concurrency was faster but defeats the purpose. In conclusion in my experience no parallelism will count faster than just single process/single thread mainly due to overhead (i think) * - systx - Apr 19, 2017 (Apr 18, 2017 11:41 PM)obby Wrote: Multiprocessing requires locking/releasing due to needing to be concurrent. However 4 processes counting to 1 million without concurrency was faster but defeats the purpose. Your last paragraph is exactly what I was thinking. I decided to make a program that counts from a range of different numbers. For example, one thread would count from 1-100 while another one at the same time ran from 100-200 and so on. Hope this helps someone else with this problemo! |