-
Notifications
You must be signed in to change notification settings - Fork 638
optimize DoubleConverter #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the PR. Would it be possible to see the code for the benchmark? |
pls ignore this pr, I will fix a bug in this pr. and will also upload benchmark file |
Benchmark Mode Cnt Score Error Units import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import quickfix.FieldConvertError;
import quickfix.field.converter.DoubleConverter;
/**
* Created by Baoyi Chen on 2017/1/25.
*/
public class DoubleConverterBenchmark {
private static final String[] DATASET = new String[]{"0",".0",".1","1234","0987654321","1234567890.0987654321","-0","-1234567890.0987654321","-.0"};
@Benchmark
public void measureRaw() throws Exception {
for(String str : DATASET){
DoubleConverter.convert(str);
}
}
@Benchmark
public void measureFast() throws Exception {
for(String str : DATASET){
FastDoubleConverter.convert(str);
}
}
@Benchmark
public void measurePR34() throws Exception {
for(String str : DATASET){
PR34DoubleConverter.convert(str);
}
}
public static void main(String[] args) throws RunnerException, FieldConvertError {
Options opt = new OptionsBuilder()
.include(DoubleConverterBenchmark.class.getSimpleName())
.warmupIterations(5)
.measurementIterations(10)
.shouldDoGC(false)
.forks(1)
.build();
new Runner(opt).run();
}
} |
I already updated this pr , please check |
It is my understanding that your code is 10 times faster. Is there a spec for FIX double values? I understand that your implementation is faster because you don't trim the input string, you don't handle hex numbers, etc. Am I correct? |
Hi @MartyIX , |
Hi @MartyIX I just convert |
@leonchen83 I believe this PR should add a unit test too. To verify that it follows the spec:
@chrjohn What do you think about the PR? Do you believe that it is backward compatible? |
Hi @MartyIX , |
found a bug about IntConverter.convert, more detail pls see test case in this pr |
@leonchen83 Could you elaborate on the problem? 100 looks like an Integer to me ;) |
according to Sequence of digits without commas or decimals and optional sign character (ASCII characters "-" and "0" - "9" ). The sign character utilizes one byte (i.e. positive int is "99999" while negative int is "-99999"). Note that int values may contain leading zeros (e.g. "00023" = "23").
Examples:
723 in field 21 would be mapped int as |21=723|.
-723 in field 12 would be mapped int as |12=-723|
The following data types are based on int. but |
the root cause is |
Sounds OK to me. I don't think we should change the implementation and leave it based on what |
so you mean |
Let me ask this way: is there a benefit to introduce a restriction to accept only ISO-LATIN digits in that method? |
got the point ,thx @chrjohn |
No problem, thanks for the PR. I'd like to accept it with the DoubleConverter stuff that you did. |
Benchmark Mode Cnt Score Error Units
DoubleConverterBenchmark.measureFast thrpt 10 1204994.113 ± 11444.945 ops/s
DoubleConverterBenchmark.measureRaw thrpt 10 575634.679 ± 6665.589 ops/s