Python Forum
code running for more than an hour now, yet didn't get any result, what should I do?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code running for more than an hour now, yet didn't get any result, what should I do?
#2
Why do you loop over range(1, i+1) and then subtract 1 from i?

This is not correct.
 n = int(xb/dx)
  m = int(yb/dy)
  l = int(zb/dz)
It is only correct if xa, ya and za are all zero.

I have no idea why it would take hours. I set dz = 1 and the program takes 1.3 seconds on my computer. I set dz = 0.2 and it took 5 times longer (5.3 seconds). I set dz = 0.02 and it took 10 times longer than that (50 seconds). I would expect dz = 0.002 should take 500 seconds. A long time to wait, but not hours.

For the function p this is a particularly inefficient way to compute the total. In your particular example cos(ya+(j-1)*dy) is computed for each iteration of the "k" loop. The value is the same each time. You are calling math.cos() 500 times more often then is needed, and you are calling math.sin() 500,000 times more often than is needed.
Reply


Messages In This Thread
RE: code running for more than an hour now, yet didn't get any result, what should I do? - by deanhystad - Apr-06-2022, 03:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 917 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 535 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 669 Nov-10-2023, 08:09 AM
Last Post: akbarza
Question Sqlite3 how to know when cursor.execute didn't return anything ? SpongeB0B 2 991 Dec-18-2022, 06:13 PM
Last Post: deanhystad
  help me simple code result min and max number abrahimusmaximus 2 1,050 Nov-12-2022, 07:52 AM
Last Post: buran
  Code running many times nad not just one? korenron 4 1,505 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 4,145 Jul-01-2022, 02:51 PM
Last Post: maiya
  Can a program execute code in iPython shell and get result? deanhystad 3 1,907 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  Needing to Check Every Quarter Hour bill_z 10 3,354 Feb-09-2022, 07:23 PM
Last Post: menator01
  Why is this Python code running twice? mcva 5 5,605 Feb-02-2022, 10:21 AM
Last Post: mcva

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020