Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab 4 Using threads. This lab is a warm-up for the next assignment. We will learn to build a multi-threaded application. You will write a
Lab 4 Using threads.
This lab is a warm-up for the next assignment. We will learn to build a multi-threaded application. You will write a function that will simulate a long task. You will call the first method a number of times sequentially and record the time it take to complete. The will call the first method again but in a threaded manner and time the execution and then compare the two times.
Create three functions:
- Create a function to the following:
- Take a string argument (name).
- Create a loop that will run for 100_000 time. In this loop, the program will sleep 0.000_1 seconds.
- After the completion of the loop, prints its name and a brief message.
- Create a second function to do the following:
- Takes a number argument (times to execute the loop).
- Store the current time.
- Call the function in step 1 the required number of times (sequentially).
- Check the elapse time after the above calls complete.
- Print the results as well as a brief messag
- Create a third function to do the following:
- Takes a number argument (times to execute the loop).
- Store the current time.
- Call the function in step 1 the required number of times (as threads).
- Check the elapse time after the above calls complete
- Print the results as well as a brief message
- Write the statements
- to call the function in step 2 ten times
- to call the function in step 3 ten times
Code to be done in python. I need to create .py file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started