Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 - Timing Dasetions fues inh arm. tartin. Bearter nile u o ia tif if is rumatipsiti tf + tser. fabctinateent fibr, ta) fichitad

image text in transcribed
image text in transcribed
image text in transcribed
Part 1 - Timing Dasetions fues inh arm. tartin. Bearter nile u o ia tif if is rumatipsiti tf + tser. fabctinateent fibr, ta) fichitad beherter be tarietnat: ipthat timiratctime if s(1) +4.36 an 1 + t A an Part 2 o Better Prowit the tam alreble. Part 3 - More Aosader foucthau tetanin flogipy fin(au Jand (i), a) Module 3 Lab: Timing Functions Part 1 - Timing Functions Start by writing a basic function time_function(func, args) that returns the number of scoonds to run func with argn. TineFunctions.py contains some triak that should have a nunning time ratio of 10x to help test your function. Starter code Expected behavior in terminal: $ python3 TineFunctions.py t(t.1)=4.99=n t(t,2)=51,9nn Part 2 - Better Results Running your function one time leaves a lot of room for nolst - other proceses are vylug for resources on your computer. We ean get a better reading by running the function multiple times and returning just the minimum. Note that we should use the minimum time from multiple trinks, not the average, as that in probably the trial with the least amount of noise. Modify tiee function to take an extra parameter, n_tria1s, which defaults to 10. Retum the minimum time from 10 trials. Note - python let's you use "infinity" with float('inf'). This may be lelpful bere. Your method as-is probably can only time functions that take a single argument. This is an issue if you want to handle functions with an arbitrary number of parameters. Say we have two addition methods: 1 der add_2_nuss (p1, p2): return p1+p2 det add_3_nuen (p1,p2,p3)= return p1+p2+p3 If we try to time these functions, we'll get an error: >>. time_function(add_2_nues, 3,4,ntrials10 ) TypeEtrer: tine function() got multiple values for arguent 'n_triald' Pythou thinks 4 is supposed to be the mumber of triak, rather than a socond argument. We can use tuple unpacking to handle an arbitrary nianber of arguments instead. We'll pack all of our arguments into a tuple, then unpack that tuple when we call the function we want to time: Pp) def foo (f, args): roturn f (*args) * the - whpacks "args" into separate argumenta P>? foo(add_2_nums, (3,4)) 7 35> 100( add, 3,nums, (3,4,5)) 12. Add a function time function flexible() that operates ar above, but it in midile parameter should be a tuple of anguncents: - I. the function to be rexated - argn - a tuple of an arbitzary zumber of arguments to be pasoed to f - D_trials - che aumber of traln your want to rum

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions