code: def test_clip_l2_grad_norm_speed():
      logger = getLogger(__name__)
  
      # Speed difference is large when model is large
      model = nn.Sequential(
          nn.Linear(2, 1000),
          nn.ReLU(),
          nn.Linear(1000, 1000),
          nn.ReLU(),
          nn.Linear(1000, 3),
      )
      x = torch.rand(7, 2)
  
      def backward():
          model.zero_grad()
          loss = model(x).mean()
          loss.backward()
  
      # Threshold large enough not to affect grads
      th = 10000
      backward()
  
      def torch_clip():
          nn.utils.clip_grad_norm_(model.parameters(), th)
  
      torch_time = timeit.timeit(torch_clip, number=100)
      logger.debug("torch.nn.utils.clip_grad_norm_ took %s", torch_time)
  
      def our_clip():
          clip_l2_grad_norm_(model.parameters(), th)
  
      our_time = timeit.timeit(our_clip, number=100)
      logger.debug("pfrl.misc.clip_l2_grad_norm_ took %s", our_time)
  
      assert our_time < torch_time
  
file_path: pfrl/tests/utils_tests/test_clip_l2_grad_norm.py
imports: import timeit
  from logging import getLogger
  import numpy
  import pytest
  import torch
  from torch import nn
  from pfrl.utils import clip_l2_grad_norm_
label_desc: Use image node_id 5 for calling a global function with example usage: test_clip_l2_grad_norm_speed() without return types