Coder Social home page Coder Social logo

algorism's People

Contributors

gapry avatar

Watchers

 avatar

algorism's Issues

Google Benchmark Incompatibility with C++ Modules as Template Arguments

I have encountered an issue when trying to use C++ modules with Google Benchmark. Specifically, Google Benchmark fails to compile when attempting to use a class from a C++ module as a template argument.

You can use the following design to reproduce the issue:

#include <benchmark/benchmark.h>

import algorism.string;

template<typename TString>
static void StringAppendCStr(benchmark::State& state) {
  const char* const s1 = "Hi Hi! ";
  const char* const s2 = "I go to school by bus!";

  TString bench_str(s1);
  for (auto _ : state) {
    bench_str += s2;
  }
}

static void BM_Algorism_StringAppendCStr(benchmark::State& state) {
  StringAppendCStr<algorism::string>(state);
}

static void BM_STD_StringAppendCStr(benchmark::State& state) {
  StringAppendCStr<std::string>(state);
}

BENCHMARK(BM_Algorism_StringAppendCStr)->Iterations(1024);
BENCHMARK(BM_STD_StringAppendCStr)->Iterations(1024);

The corresponding error report:

error: no matching function for call to 'StringAppendCStr'
StringAppendCStr<algorism::string>(state);

At the moment, I am using the following workaround by not using the templates with the module class and instead defining benchmark functions for each type:

void BM_Algorism_StringAppendCStr(benchmark::State& state) {
  const char* const s1 = "Hi Hi! ";
  const char* const s2 = "I go to school by bus!";

  algorism::string bench_str(s1);
  for (auto _ : state) {
    bench_str += s2;
  }
}
BENCHMARK(BM_Algorism_StringAppendCStr)->Iterations(1024);

void BM_STD_StringAppendCStr(benchmark::State& state) {
  const char* const s1 = "Hi Hi! ";
  const char* const s2 = "I go to school by bus!";

  std::string bench_str(s1);
  for (auto _ : state) {
    bench_str += s2;
  }
}
BENCHMARK(BM_STD_StringAppendCStr)->Iterations(1024);

I mention it here because it's not critical at the moment. I'll try to fix it when I have time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.