H
Hicham Mouline
Hello
we have a perf critical function that calculates for 1 thing, many
operations, and returns for each 1 result and 1 code.
codes and results are outputs, operationSet is the input.
Calculate( CalcCode codes[], double results[], const CalcOperationSet&
operationSet, int thing)
{
if ( operationSet.IsSet( ... ) ) {
// do operation and store in results
}
...
}
Before that, I had
Calculate ( std::map<CalcOperation, pair<CalcCode, double> >& output, const
CalcOperationSet& operationSet, int thing)
but it is a 4 times slower than the above version in a typical usage.
So we will go with the native array based solution.
Note, the size of the array is equal to the size of the set. The array is
preallocated outside of the loop calling Calculate.
enum CalcOperation { // 3rd party lib
OP1 = 4023,
OPtwo = 2349,
OPthree = 4,
....
// 500 elements
};
I wish to index the operations set in operationSet, so that I can extract a
size_t index to use for codes and results.
The calling contexts have a static number of operations you pass in the set,
but there are many different calling contexts.
1 context would look like:
CalcOperationSet operationSet; operationSet.set( OP1 );
operationSet.set( OPthree ); operationSet.set( OPtwo );
double results[3]; CalcCode codes[3];
// somehow associate OP1 with 0, OPthree with 1 and OPtwo with 2
// of course, OP1 with 0 depends on the context , here we have a set with
just 3 elements
// can we determine the order of insertion
for (size_t s=0; s<1000; ++s)
Calculate(results, codes, operationSet, things );
regards,
we have a perf critical function that calculates for 1 thing, many
operations, and returns for each 1 result and 1 code.
codes and results are outputs, operationSet is the input.
Calculate( CalcCode codes[], double results[], const CalcOperationSet&
operationSet, int thing)
{
if ( operationSet.IsSet( ... ) ) {
// do operation and store in results
}
...
}
Before that, I had
Calculate ( std::map<CalcOperation, pair<CalcCode, double> >& output, const
CalcOperationSet& operationSet, int thing)
but it is a 4 times slower than the above version in a typical usage.
So we will go with the native array based solution.
Note, the size of the array is equal to the size of the set. The array is
preallocated outside of the loop calling Calculate.
enum CalcOperation { // 3rd party lib
OP1 = 4023,
OPtwo = 2349,
OPthree = 4,
....
// 500 elements
};
I wish to index the operations set in operationSet, so that I can extract a
size_t index to use for codes and results.
The calling contexts have a static number of operations you pass in the set,
but there are many different calling contexts.
1 context would look like:
CalcOperationSet operationSet; operationSet.set( OP1 );
operationSet.set( OPthree ); operationSet.set( OPtwo );
double results[3]; CalcCode codes[3];
// somehow associate OP1 with 0, OPthree with 1 and OPtwo with 2
// of course, OP1 with 0 depends on the context , here we have a set with
just 3 elements
// can we determine the order of insertion
for (size_t s=0; s<1000; ++s)
Calculate(results, codes, operationSet, things
regards,