1+ import time
2+ import numpy as np
3+
4+
5+ # --- Prime Function --- #
6+ primeList = []
7+ def primeCounter (countUpTo ):
8+ list = [x for x in range (0 ,countUpTo )]
9+
10+ # Get the value in the list
11+ for i in range (len (list )):
12+ # From 2 to the value, check to see if it is a prime; if the remainder is zero, not a prime; else, append prime number to the primeList
13+ for k in range (2 , i ):
14+ if i % k == 0 :
15+ break
16+ else :
17+ primeList .append (i )
18+
19+ print (primeList )
20+
21+ # --- Primes to 100 --- #
22+ # Start timer
23+ startTimer = time .perf_counter ()
24+ startTimer2 = time .process_time ()
25+
26+ primeCounter (101 )
27+
28+ endTimer = time .perf_counter ()
29+ endTimer2 = time .process_time ()
30+
31+ print (f"Task Finished In Performance: { endTimer - startTimer :0.8f} s\n Task Finished In Process/CPU/Kernel + User Space: { endTimer2 - startTimer2 :0.8f} s" )
32+
33+ # --- Primes to 1000 --- #
34+ # Start timer
35+ startTimer = time .perf_counter ()
36+ startTimer2 = time .process_time ()
37+
38+ primeCounter (1001 )
39+
40+ endTimer = time .perf_counter ()
41+ endTimer2 = time .process_time ()
42+
43+ print (f"Task Finished In Performance: { endTimer - startTimer :0.8f} s\n Task Finished In Process/CPU/Kernel + User Space: { endTimer2 - startTimer2 :0.8f} s" )
44+
45+ # --- Primes to 10000 --- #
46+ # Start timer
47+ startTimer = time .perf_counter ()
48+ startTimer2 = time .process_time ()
49+
50+ primeCounter (10001 )
51+
52+ endTimer = time .perf_counter ()
53+ endTimer2 = time .process_time ()
54+
55+ print (f"Task Finished In Performance: { endTimer - startTimer :0.8f} s\n Task Finished In Process/CPU/Kernel + User Space: { endTimer2 - startTimer2 :0.8f} s" )
56+
57+ # --- Primes to 1000000 --- #
58+ # Start timer
59+ startTimer = time .perf_counter ()
60+ startTimer2 = time .process_time ()
61+
62+ primeCounter (1000001 )
63+
64+ endTimer = time .perf_counter ()
65+ endTimer2 = time .process_time ()
66+
67+ print (f"Task Finished In Performance: { endTimer - startTimer :0.8f} s\n Task Finished In Process/CPU/Kernel + User Space: { endTimer2 - startTimer2 :0.8f} s" )
0 commit comments