Created
June 27, 2011 10:02
-
-
Save joseph-montanez/1048607 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
gnatmake -O3 -gnatv -gnaty main.adb | |
time ./main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Ada.Text_IO; | |
with Ada.Calendar; | |
with GNAT.Calendar.Time_IO; | |
with Ada.Strings; | |
with Ada.Strings.Fixed; | |
procedure Main is | |
type Max_Number_List is array (Positive range <>) of Long_Long_Integer; | |
Max_Number : Long_Long_Integer := 0; | |
Max_Numbers : Max_Number_List := ( | |
10000000, 10000000, 10000000, 10000000, 10000000 | |
); | |
task type Run_Loop is | |
entry Start (Max_Number : Long_Long_Integer); | |
entry Result (Return_Value : out Long_Long_Integer); | |
entry Stop; | |
end Run_Loop; | |
task body Run_Loop is | |
Current_Time : Ada.Calendar.Time; | |
Last_Number : Long_Long_Integer := 0; | |
begin | |
accept Start (Max_Number : Long_Long_Integer); | |
Current_Time := Ada.Calendar.Clock; | |
Ada.Text_IO.Put_Line ("Started: " & GNAT.Calendar.Time_IO.Image ( | |
Current_Time, "%Y-%m-%d %T.%e" | |
) & Long_Long_Integer'Image (Max_Number)); | |
for I in 1 .. Max_Number loop | |
Last_Number := I * I; | |
select | |
accept Stop; | |
exit; | |
else | |
null; | |
end select; | |
end loop; | |
accept Result (Return_Value : out Long_Long_Integer) do | |
Return_Value := Last_Number; | |
end Result; | |
end Run_Loop; | |
Run_Loop_Tasks : array (Max_Numbers'Range) of Run_Loop; | |
Last_Number : Long_Long_Integer; | |
begin | |
for Max_Number_Index in Max_Numbers'Range loop | |
Max_Number := Max_Numbers (Max_Number_Index); | |
Run_Loop_Tasks (Max_Number_Index).Start (Max_Number); | |
end loop; | |
Ada.Text_IO.Put_Line ("All are started!"); | |
for Max_Number_Index in Max_Numbers'Range loop | |
Max_Number := Max_Numbers (Max_Number_Index); | |
Run_Loop_Tasks (Max_Number_Index).Result (Last_Number); | |
Ada.Text_IO.Put_Line ( | |
Ada.Strings.Fixed.Trim ( | |
Long_Long_Integer'Image (Max_Number), Ada.Strings.Left | |
) & " ran for" & | |
Long_Long_Integer'Image (Last_Number) | |
); | |
end loop; | |
end Main; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
import urllib.request | |
import time | |
import datetime | |
max_numbers = [100000, 1000000, 1000000, 10000000, 10000000] | |
def run_loop(max_number): | |
print("Started:", datetime.datetime.now(), max_number) | |
last_number = 0; | |
for i in range(1, max_number + 1): | |
last_number = i * i | |
return last_number | |
def main(): | |
with concurrent.futures.ProcessPoolExecutor(max_workers=len(max_numbers)) as executor: | |
future_to_url = {} | |
for max_number in max_numbers: | |
future_to_url[executor.submit(run_loop, max_number)] = max_number | |
for future in concurrent.futures.as_completed(future_to_url): | |
number = future_to_url[future] | |
if future.exception() is not None: | |
print('%r generated an exception: %s' % (number, | |
future.exception())) | |
else: | |
print('%r ran for %d' % (number, future.result())) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
time python3.2 main.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment