| 347 | } |
| 348 | |
| 349 | static void BM_CSE(int iters, int op_nodes) { |
| 350 | testing::StopTiming(); |
| 351 | string s; |
| 352 | for (int in = 0; in < 10; in++) { |
| 353 | s += strings::Printf("node { name: 'in%04d' op: 'Input'}", in); |
| 354 | } |
| 355 | random::PhiloxRandom philox(301, 17); |
| 356 | random::SimplePhilox rnd(&philox); |
| 357 | for (int op = 0; op < op_nodes; op++) { |
| 358 | s += strings::Printf( |
| 359 | "node { name: 'op%04d' op: 'Mul' attr { key: 'T' value { " |
| 360 | "type: DT_FLOAT } } input: ['in%04d', 'in%04d' ] }", |
| 361 | op, rnd.Uniform(10), rnd.Uniform(10)); |
| 362 | } |
| 363 | |
| 364 | bool first = true; |
| 365 | while (iters > 0) { |
| 366 | Graph* graph = new Graph(OpRegistry::Global()); |
| 367 | InitGraph(s, graph); |
| 368 | int N = graph->num_node_ids(); |
| 369 | if (first) { |
| 370 | testing::SetLabel(strings::StrCat("Per graph node. Nodes: ", N)); |
| 371 | first = false; |
| 372 | } |
| 373 | { |
| 374 | testing::StartTiming(); |
| 375 | OptimizeCSE(graph, nullptr); |
| 376 | testing::StopTiming(); |
| 377 | } |
| 378 | iters -= N; // Our benchmark units are individual graph nodes, |
| 379 | // not whole graphs |
| 380 | delete graph; |
| 381 | } |
| 382 | } |
| 383 | BENCHMARK(BM_CSE)->Arg(1000)->Arg(10000); |
| 384 | |
| 385 | } // namespace |
nothing calls this directly
no test coverage detected