Skip to content

Performance deficite dute to map key type std::string #1

@Expander

Description

@Expander

Dear Frank Thomas,

I'm planning to use your SLHAea package in my own spectrum generator because it looks very elegant and seems to be easy to use.

However, speed is a critical point for me, so I wonder how SLHAea performs compared to SLHALib (http://www.feynarts.de/slha/) or other hand-written SLHA libraries? My wish would be that reading and writing time together is much smaller than 0.1 ms. Have you done some speed comparisons with other libraries?

There is one problematic point which I have in mind: You are using std::string as map key in your examples:

  ifstream ifs("slha1.txt");
  Coll input(ifs);

  cout << "tan(beta) = "        << input["MINPAR"][3][1] << '\n';
  cout << "m_top(pole) line:\n" << input["SMINPUTS"][6]  << '\n';
  cout << "SMINPUTS block:\n"   << input["SMINPUTS"];

It could be that this is rather slow compared to an integer key (depending on the std::map implementation). So, using enums as an alternative would probably help here.

One possibility to achieve this would be to make the key type a template parameter which can be chosen by the user at compile time

  template <class key_type = std::string>
  class Coll { ... };

  namespace SLHAea {
     enum BlockNames : int { MINPAR, SMINPUTS, ... };
  }

  int main() {
    ifstream ifs("slha1.txt");
    Coll<SLHAea::BlockNames> input(ifs);

    cout << "tan(beta) = "        << input[SLHAea::MINPAR][3][1] << '\n';
    cout << "m_top(pole) line:\n" << input[SLHAea::SMINPUTS][6]  << '\n';
    cout << "SMINPUTS block:\n"   << input[SLHAea::SMINPUTS];
  }

What do you think about this option?

Best regards,
Alexander Voigt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions