tensorflow/core/kernels/save_op_test.cc
// Benchmark-related code below.
Benchmark-related code below.
Benchmark - related code below .
void BM_LargeTensorWrite(::testing::benchmark::State& state) {
  const int num_elements = state.range(0);
  Tensor tensor(DT_FLOAT, TensorShape({num_elements}));
  tensor.flat<float>().setZero();
  const tstring temp_filename =
      io::JoinPath(testing::TmpDir(), "benchmark_checkpoint");
  auto root = Scope::NewRootScope().ExitOnError();
  const tstring tensor_name = "my_tensor";
  ops::Save(root, temp_filename, {tensor_name}, {{tensor}});
  SessionOptions session_options;
  session_options.config.mutable_graph_options()
      ->mutable_optimizer_options()
      ->set_opt_level(tensorflow::OptimizerOptions::L0);
  TF_CHECK_OK(root.status());
  Graph* g = new Graph(OpRegistry::Global());
  TF_CHECK_OK(root.ToGraph(g));
  VLOG(1) << "Save op's output path: " << temp_filename;
  VLOG(1) << "# nodes in Graph: " << g->num_nodes();
  test::Benchmark("cpu", g, &session_options, nullptr, nullptr, "",
                   false)
      .Run(state);
}
void BM_LargeTensorWrite ( :: testing :: benchmark :: State & state ) { const int num_elements = state . range ( 0 ) ; Tensor tensor ( DT_FLOAT , TensorShape ( { num_elements } ) ) ; tensor . flat < float > ( ) . setZero ( ) ; const tstring temp_filename = io :: JoinPath ( testing :: TmpDir ( ) , " " ) ; auto root = Scope :: NewRootScope ( ) . ExitOnError ( ) ; const tstring tensor_name = " " ; ops :: Save ( root , temp_filename , { tensor_name } , { { tensor } } ) ; SessionOptions session_options ; session_options . config . mutable_graph_options ( ) -> mutable_optimizer_options ( ) -> set_opt_level ( tensorflow :: OptimizerOptions :: L0 ) ; TF_CHECK_OK ( root . status ( ) ) ; Graph * g = new Graph ( OpRegistry :: Global ( ) ) ; TF_CHECK_OK ( root . ToGraph ( g ) ) ; VLOG ( 1 ) << " " << temp_filename ; VLOG ( 1 ) << " " << g -> num_nodes ( ) ; test :: Benchmark ( " " , g , & session_options , nullptr , nullptr , " " , false ) . Run ( state ) ; }
Benchmark-related code below.
Benchmark - related code below .
// 4 * num_elements bytes total , since sizeof(float) == 4. // Builds the graph. // Disables optimizations. /*old_benchmark_api*/