Comments (6)
testing values and execution time:
0E99999999 0.2 seconds
0E999999999 2.3 seconds
0E9999999999 23 seconds
0E99999999999 4m3.176s
from re.
the following solution was suggested by Chris Owen:
(in src/json/decode.c)
static inline double mypower10(uint64_t e)
{
double n, p;
n = 1.0;
p = 10.0;
while (e > 0) {
if (e & 1) {
n *= p;
}
p *= p;
e >>= 1;
}
return n;
}
from re.
I have tested with a couple of different solutions, and measured the performance.
The input JSON contains some numbers with exponent, and the decoding is
repeated 10000 times.
-
use
pow
from libm: 160049 usec
(a disadvantage here is adding a dep to libm) -
use patch from Chris: 160883 usec
-
in is_number use
strtol
instead: 305448 usec
The slowest solution is number 3 (use strol).
Solution number 1 and 2 has almost the same performance.
@richaas if you agree, I can prepare a PR for solution number 2.
here is the test JSON file:
{
"array" : [
0e9,
0e99,
0e999,
0e9999,
0e99999,
0e999999,
0e9999999,
0e99999999,
0e999999999,
0e9999999999,
1e9,
1e99,
1e999,
1e9999,
1e99999,
1e999999,
1e9999999,
1e99999999,
1e999999999,
1e9999999999,
2e10,
2e100,
2e1000,
2e10000,
2e100000,
2e1000000,
2e10000000,
2e100000000,
2e1000000000,
2e10000000000,
]
}
from re.
Yes, let's go for alternative 2. How will we handle resulting numbers to large to fit in long double?
from re.
here is the PR: #88
currently there is no checks in the code for boundaries/overflow.
both the base number and the exponent number is built up by parsing in reverse
the string containing [0-9].
from re.
Issue resolved in PR #88
from re.
Related Issues (20)
- Some example about JSON may mislead in retest HOT 1
- DNS client only queries first server (in most cases) HOT 5
- add RFC 6062 HOT 2
- accept 401 to re-REGISTER without WWW-Authenticate stale=true HOT 7
- Use database insted of File
- DNS resolution does not respect local configuration (/etc/hosts, avahi *.local, nsswitch.conf, etc) HOT 1
- Is there any demo for ICE ? HOT 1
- Can't Build on Docker from source HOT 2
- Can I use libre and librem in windows applications? How to compile as dll? HOT 7
- Via header address is set before TCP connection is established
- How to use rtmp_send_video to publish H264 frame?
- Issue with RTP Video over Network
- Upstream .so name versioning?
- Compilation with musl-libc fails
- libre can work based on the thirdpary Lwip?
- SIGABRT after tcp_close_handler derefs conn one too many times (race condition on socket close) HOT 2
- auth won't work for binary passwords containing zero byte characters
- config with sip device
- Shani gujjar
- WEB
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from re.