code: def sample_perf(nb, n=30):
      samples = pd.DataFrame(
          pd.np.NaN,
          index=pd.MultiIndex.from_product(
              (range(n), ["nbformat"] + JUPYTEXT_FORMATS),
              names=["sample", "implementation"],
          ),
          columns=pd.Index(["size", "read", "write"], name="measure"),
      )
  
      for i, fmt in samples.index:
          t0 = time.time()
          if fmt == "nbformat":
              text = nbformat.writes(nb)
          else:
              text = jupytext.writes(nb, fmt)
          t1 = time.time()
          samples.loc[(i, fmt), "write"] = t1 - t0
          samples.loc[(i, fmt), "size"] = len(text)
          t0 = time.time()
          if fmt == "nbformat":
              nbformat.reads(text, as_version=4)
          else:
              jupytext.reads(text, fmt)
          t1 = time.time()
          samples.loc[(i, fmt), "read"] = t1 - t0
      return samples
  
file_path: jupytext/demo/Benchmarking Jupytext.py
imports: import time
  import copy
  import pandas
  import plotly.graph_objects
  from plotly.colors import DEFAULT_PLOTLY_COLORS
  import nbformat
  import jupytext
label_desc: Use image node_id 1 for calling a global function with example usage: sample_perf(nb, n) and returns: samples