code: def test_time_profiler(batch_size, n_class, ext_name, tmpdir):
      nn.clear_parameters()
  
      ctx = get_extension_context(ext_name)
      nn.set_default_context(ctx)
  
      x = nn.Variable.from_numpy_array(
          np.random.normal(size=(batch_size, 3, 16, 16))
      )
      t = nn.Variable.from_numpy_array(
          np.random.randint(low=0, high=n_class, size=(batch_size, 1))
      )
  
      y = simple_cnn(x, t, n_class)
  
      tp = TimeProfiler(ext_name, device_id=ctx.device_id)
      for i in range(5):
          with tp.scope("forward"):
              y.forward(
                  clear_no_need_grad=True,
                  function_pre_hook=tp.pre_hook,
                  function_post_hook=tp.post_hook,
              )
  
          with tp.scope("backward"):
              y.backward(
                  clear_buffer=True,
                  function_pre_hook=tp.pre_hook,
                  function_post_hook=tp.post_hook,
              )
  
          tp.calc_elapsed_time(["forward", "backward", "summary"])
  
      tp()
      tp.to_csv(out_dir=str(tmpdir))
  
imports: import pytest
  import nnabla
  import numpy
  from nnabla.ext_utils import get_extension_context, list_extensions
  from nnabla.utils.inspection import TimeProfiler
  from .models import simple_cnn
label_desc: Use image node_id 1 for calling a global function with example usage: test_time_profiler(batch_size, n_class, ext_name, tmpdir) without return types