Bird
Raised Fist0
Testing Fundamentalstesting~20 mins

Identifying performance bottlenecks in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Performance Bottleneck Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary cause of a CPU bottleneck in software performance?

Imagine your computer is like a kitchen. The CPU is the chef who prepares meals. What usually causes the chef to slow down the whole kitchen?

AThe kitchen has too many ovens but not enough chefs
BThe chef has too many tasks to do at once and can't keep up
CThe ingredients are delivered late to the kitchen
DThe kitchen is too big and chefs have to walk too far
Attempts:
2 left
💡 Hint

Think about what limits the chef's speed directly.

❓ Predict Output
intermediate
2:00remaining
What is the output of this Python code simulating a slow function call?

Consider this code that simulates a slow function by sleeping. What will be printed?

Testing Fundamentals
import time
start = time.time()
for _ in range(3):
    time.sleep(0.5)
end = time.time()
print(round(end - start, 1))
A3.0
B0.5
C1.5
D1.0
Attempts:
2 left
💡 Hint

Each sleep lasts 0.5 seconds and runs 3 times.

❓ assertion
advanced
2:00remaining
Which assertion correctly checks that a function runs under 2 seconds?

You want to test that process_data() finishes in less than 2 seconds. Which assertion is correct?

Testing Fundamentals
import time
start = time.time()
process_data()
end = time.time()
# Which assertion below is correct?
Aassert (end - start) < 2
Bassert (start - end) < 2
Cassert (end + start) < 2
Dassert (end * start) < 2
Attempts:
2 left
💡 Hint

Think about how to measure elapsed time.

🔧 Debug
advanced
2:00remaining
Identify the performance bottleneck in this code snippet

Look at this Python code that processes a list. What causes the slowdown?

Testing Fundamentals
data = list(range(100000))
result = []
for i in data:
    if i % 2 == 0:
        result.append(i)
    else:
        result.append(i*2)
print(len(result))
AThe print statement slows down the program
BUsing modulo operator (%) causes errors
CThe range function is slow for large numbers
DUsing a for-loop with append instead of list comprehension
Attempts:
2 left
💡 Hint

Think about how Python handles list building efficiently.

❓ framework
expert
2:00remaining
Which tool is best suited to identify database query bottlenecks in a web app?

You want to find slow database queries causing delays in your web application. Which tool helps best?

AA profiler that tracks SQL query execution times
BA unit testing framework for UI components
CA code linter that checks syntax errors
DA version control system like Git
Attempts:
2 left
💡 Hint

Focus on tools that measure performance, not code correctness.

Practice

(1/5)
1. What is a performance bottleneck in software testing?
easy
A. A part of the software that slows down the whole system
B. A feature that adds new functionality
C. A test case that always passes
D. A tool used to write code faster

Solution

  1. Step 1: Understand the meaning of bottleneck

    A bottleneck is something that limits or slows down a process.
  2. Step 2: Apply this to software performance

    In software, a bottleneck is the slow part that affects the whole system's speed.
  3. Final Answer:

    A part of the software that slows down the whole system -> Option A
  4. Quick Check:

    Performance bottleneck = slow part [OK]
Hint: Bottleneck means slowest part slowing everything [OK]
Common Mistakes:
  • Confusing bottleneck with new features
  • Thinking bottleneck is a test case
  • Mixing bottleneck with coding tools
2. Which of the following is the correct way to measure execution time in Python for identifying bottlenecks?
easy
A. import time; start = time.time(); # code; end = time.time(); print(end - start)
B. import datetime; print(datetime.now())
C. print('Execution time')
D. time.sleep(5)

Solution

  1. Step 1: Identify timing method for measuring code duration

    Using time.time() before and after code gives elapsed seconds.
  2. Step 2: Check options for correct timing usage

    import time; start = time.time(); # code; end = time.time(); print(end - start) correctly measures start and end time and calculates difference.
  3. Final Answer:

    import time; start = time.time(); # code; end = time.time(); print(end - start) -> Option A
  4. Quick Check:

    Use time.time() to measure duration [OK]
Hint: Use time.time() before and after code [OK]
Common Mistakes:
  • Using print statements without timing
  • Using datetime.now() without calculating difference
  • Using sleep to measure time
3. Consider this Python code snippet measuring a function's execution time:
import time
def slow_function():
    total = 0
    for i in range(1000000):
        total += i
start = time.time()
slow_function()
end = time.time()
print(round(end - start, 2))
What is the expected output type?
medium
A. The sum of numbers from 0 to 999999
B. An error because of missing return
C. A float number showing seconds taken
D. A string 'round' printed

Solution

  1. Step 1: Understand what the code measures

    The code measures time before and after running slow_function and prints the difference rounded to 2 decimals.
  2. Step 2: Analyze output type

    round(end - start, 2) returns a float number representing seconds elapsed.
  3. Final Answer:

    A float number showing seconds taken -> Option C
  4. Quick Check:

    Timing code prints float seconds [OK]
Hint: Timing code prints float seconds elapsed [OK]
Common Mistakes:
  • Thinking it prints sum instead of time
  • Expecting an error due to no return
  • Confusing round function output
4. You have this code snippet to find a bottleneck:
import time
start = time.time()
for i in range(1000000):
    pass
print(end - start)
What is the error and how to fix it?
medium
A. Range should be 1000 instead of 1000000
B. Missing import statement for time module
C. Use print(start - end) instead
D. Variable 'end' is not defined; define end = time.time() before print

Solution

  1. Step 1: Identify the error in variable usage

    The variable 'end' is used in print but never assigned, causing a NameError.
  2. Step 2: Fix by assigning end before print

    Assign end = time.time() after the loop and before print to measure elapsed time.
  3. Final Answer:

    Variable 'end' is not defined; define end = time.time() before print -> Option D
  4. Quick Check:

    Define end = time.time() before print [OK]
Hint: Always assign end time before printing elapsed [OK]
Common Mistakes:
  • Forgetting to assign end time
  • Changing range unnecessarily
  • Subtracting times in wrong order
5. You run a profiler on your web app and find that database queries take 80% of the total time. What is the best next step to improve performance?
hard
A. Add more logging to the application
B. Optimize or reduce the number of database queries
C. Increase the size of the frontend assets
D. Rewrite the UI in a different framework

Solution

  1. Step 1: Analyze profiler results

    Profiler shows database queries consume most time, indicating a bottleneck there.
  2. Step 2: Choose action targeting bottleneck

    Optimizing or reducing queries directly addresses the slowest part to improve speed.
  3. Final Answer:

    Optimize or reduce the number of database queries -> Option B
  4. Quick Check:

    Fix bottleneck by optimizing slowest part [OK]
Hint: Fix bottleneck by improving slowest part first [OK]
Common Mistakes:
  • Changing unrelated parts like UI or logging
  • Ignoring profiler data
  • Adding features instead of fixing speed
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard