code: def test_fractional_timer():
      N = 10
  
      def check_fraction(timer, ft):
          # The running fraction should be approximately equal to the
          # sum of last N "measurement" intervals over the sum of last
          # 2N intervals (not 2N - 1 or 2N + 1)
          actual = ft.running_fraction
          expected = sum(timer.durations[1][-N:]) / (
              sum(timer.durations[0][-N:] + timer.durations[1][-N:])
          )
          assert actual == pytest.approx(expected)
  
      timer = RandomTimer()
      ft = FractionalTimer(n_samples=N, timer=timer)
      for _ in range(N):
          ft.start_timing()
          ft.stop_timing()
      assert len(timer.timings) == N * 2
      assert ft.running_fraction is None
  
      ft.start_timing()
      ft.stop_timing()
      assert len(timer.timings) == (N + 1) * 2
      assert ft.running_fraction is not None
      check_fraction(timer, ft)
  
      for _ in range(N * 10):
          ft.start_timing()
          ft.stop_timing()
          check_fraction(timer, ft)
  
file_path: distributed/distributed/tests/test_utils_perf.py
imports: from __future__ import annotations
  import contextlib
  import gc
  import itertools
  import random
  import re
  import pytest
  from distributed.metrics import thread_time
  from distributed.utils_perf import FractionalTimer, GCDiagnosis, disable_gc_diagnosis
  from distributed.utils_test import captured_logger, run_for
label_desc: Use image node_id 1 for calling a global function with example usage: test_fractional_timer() without return types