code: def _compare_sparse_dense(
      data_dir,
      file_name,
      mini_file_name,
      feature_dim,
      output_dim,
      density,
      batch_size,
      num_batches=3,
      num_repeat=5,
      transpose=False,
      rsp=False,
  ):
      def create_mini_path(mini_path, path, num_batches):
          """Samples batches of size: batch_size, total number: num_batches
          from the dataset files for running benchmarks"""
          if not os.path.exists(mini_path):
              last = _line_count(path) - num_batches * batch_size
              last = last if last >= 1 else 1
              start = int(rnd.uniform(1, last))
              os.system(
                  "sed -n '{},{}p' {} > {}".format(
                      start,
                      start + num_batches * batch_size,
                      repr(path),
                      repr(mini_path),
                  )
              )
              assert os.path.exists(mini_path)
  
      def run_benchmark(mini_path):
          """Run benchmarks"""
          data_shape = (feature_dim,)
          train_iter = _get_iter(mini_path, data_shape, batch_size)
          weight_row_dim = batch_size if transpose else feature_dim
          weight_shape = (weight_row_dim, output_dim)
          if not rsp:
              weight = mx.nd.random.uniform(
                  low=0, high=1, shape=weight_shape
              )
          else:
              weight = rand_ndarray(
                  weight_shape,
                  "row_sparse",
                  density=0.05,
                  distribution="uniform",
              )
          total_cost = {}
          average_cost = {}
          count = 0
          total_cost["sparse"] = 0.0
          total_cost["dense"] = 0.0
          for _ in train_iter:
              csr_data = train_iter.getdata()
              dns_data = csr_data.tostype("default")
              cost_sparse = measure_cost(
                  num_repeat,
                  False,
                  False,
                  mx.nd.sparse.dot,
                  csr_data,
                  weight,
                  transpose_a=transpose,
              )
              cost_dense = measure_cost(
                  num_repeat,
                  False,
                  False,
                  mx.nd.dot,
                  dns_data,
                  weight,
                  transpose_a=transpose,
              )
              total_cost["sparse"] += cost_sparse
              total_cost["dense"] += cost_dense
              count = count + 1
          average_cost["sparse"] = total_cost["sparse"] / count
          average_cost["dense"] = total_cost["dense"] / count
          return (average_cost["sparse"], average_cost["dense"])
  
      def print_result(average_cost_sparse, average_cost_dense):
          """Print result of comparison between sparse and dense"""
          ratio = average_cost_dense / average_cost_sparse
          fmt = "{:15.4f} {:10d} {:10d} {:10d} {:20.2f} {:15.2f} {:15.2f} {:10} {:10}"
          print(
              fmt.format(
                  density * 100,
                  batch_size,
                  output_dim,
                  feature_dim,
                  ratio,
                  average_cost_dense * 1000,
                  average_cost_sparse * 1000,
                  transpose,
                  rsp,
              )
          )
  
      mini_path = os.path.join(data_dir, mini_file_name)
      path = os.path.join(data_dir, file_name)
      create_mini_path(mini_path, path, num_batches)
      average_cost_sparse, average_cost_dense = run_benchmark(mini_path)
      print_result(average_cost_sparse, average_cost_dense)
  
file_path: mxnet/benchmark/python/sparse/dot.py
imports: import ctypes
  import os
  import time
  import argparse
  import subprocess
  import scipy.sparse
  import mxnet
  import numpy
  import numpy.random
  from mxnet.test_utils import rand_ndarray, set_default_device, assert_almost_equal, get_bz2_data
  from mxnet.base import check_call, _LIB
  from util import estimate_density
label_desc: Use image node_id 4 for calling a global function with example usage: _compare_sparse_dense(data_dir, file_name, mini_file_name, feature_dim, output_dim, density, batch_size, num_batches, num_repeat, transpose, rsp) and returns: average_cost,  average_cost