[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Reply to: [list | sender only]
Re: CIF-JSON new draft
- Subject: Re: CIF-JSON new draft
- From: Marcin Wojdyr <wojdyr@xxxxxxxxx>
- Date: Mon, 1 May 2017 18:03:00 +0100
- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;h=mime-version:in-reply-to:references:from:date:message-id:subject:to;bh=htOefb8gOooQV6Iv7tUGmcKtruoMPbYW/9wndCq+Y/c=;b=UgEpdwn2/VuO0VA1S7pYCFgla5EJvbNpx+uVZ2T47BDU+YoHeBP6pBGa7OwySv9ojJ3X++wDn+aPgyAMTasmNmSrABd1p8wB7QwuGrtXPXPXOl+8Kh+CCgZsAaTr+0Dq/yNAzBOWFVP18NrJa5zcHevAv0ogoEcOA5t3bQY4XV087TYlFQ7etIP6dFv4vD4kyUFwx5vm1o85sU6wxW7H9fcd85qXLB+VR4/8TEB0VpIZ2TEugMVWklrUIaNf7u38jLIdX22GQSUZbAjWrmVUCsE5lfppVf4VCMHFUnRyOQWu6GBF+8Ko/Yi04ENa5ho3kW1QiqNT3xwWn3u+JvZRwg==
- In-Reply-To: <MWHPR04MB051226521AF5A8F60AA4BC67E0140@MWHPR04MB0512.namprd04.prod.outlook.com>
- References: <CAM+dB2ey9kKLoZY=WE7Uy-fiWTGhQaFx7fcgODcYfhrNPwXkQw@mail.gmail.com><CACaHzQU-NPvorqZzARhnsTLaAU_tqpp9v56fJss9C9NG--ps0A@mail.gmail.com><MWHPR04MB051226521AF5A8F60AA4BC67E0140@MWHPR04MB0512.namprd04.prod.outlook.com>
>
> Since we are targeting this as a low overhead representation, which I associate with performance considerations, I am prepared to entertain arguments about performance impact. I am not, however, prepared to accept unsupported assertions about performance.
Fair enough, here is a microbenchmark for you. First using Python2.7:
$ python -m timeit -s 'import json,sys' 'f=open("numbers.json"); numbers = json.load(f)["numbers"]'
100 loops, best of 3: 10.2 msec per loop
$ python -m timeit -s 'import json,sys' 'f=open("strings.json"); numbers = [float(x) for x in json.load(f)["strings"]]'
10 loops, best of 3: 58.1 msec per loop
In this case using strings is 5x slower.
Now with Python 3.5:
$ python3 -m timeit -s 'import json,sys' 'f=open("numbers.json"); numbers = json.load(f)["numbers"]'
100 loops, best of 3: 12.7 msec per loop
$ python3 -m timeit -s 'import json,sys' 'f=open("strings.json"); numbers = [float(x) for x in json.load(f)["strings"]]'
10 loops, best of 3: 27.4 msec per loop
The difference is smaller, but still >2x.
The input files were prepared using this script:
import json
import random
numbers = [round(random.uniform(-30, 30), 3) for _ in range(100000)]
with open('numbers.json', 'w') as f:
json.dump({'numbers':numbers}, f)
with open('strings.json', 'w') as f:
json.dump({'strings':[str(x) for x in numbers]}, f)
$ du -h strings.json numbers.json
984K strings.json
788K numbers.json
Marcin
> Since we are targeting this as a low overhead representation, which I associate with performance considerations, I am prepared to entertain arguments about performance impact. I am not, however, prepared to accept unsupported assertions about performance.
Fair enough, here is a microbenchmark for you. First using Python2.7:
$ python -m timeit -s 'import json,sys' 'f=open("numbers.json"); numbers = json.load(f)["numbers"]'
100 loops, best of 3: 10.2 msec per loop
$ python -m timeit -s 'import json,sys' 'f=open("strings.json"); numbers = [float(x) for x in json.load(f)["strings"]]'
10 loops, best of 3: 58.1 msec per loop
In this case using strings is 5x slower.
Now with Python 3.5:
$ python3 -m timeit -s 'import json,sys' 'f=open("numbers.json"); numbers = json.load(f)["numbers"]'
100 loops, best of 3: 12.7 msec per loop
$ python3 -m timeit -s 'import json,sys' 'f=open("strings.json"); numbers = [float(x) for x in json.load(f)["strings"]]'
10 loops, best of 3: 27.4 msec per loop
The difference is smaller, but still >2x.
The input files were prepared using this script:
import json
import random
numbers = [round(random.uniform(-30, 30), 3) for _ in range(100000)]
with open('numbers.json', 'w') as f:
json.dump({'numbers':numbers}, f)
with open('strings.json', 'w') as f:
json.dump({'strings':[str(x) for x in numbers]}, f)
$ du -h strings.json numbers.json
984K strings.json
788K numbers.json
Marcin
_______________________________________________ cif-developers mailing list cif-developers@iucr.org http://mailman.iucr.org/cgi-bin/mailman/listinfo/cif-developers
Reply to: [list | sender only]
- Follow-Ups:
- Re: CIF-JSON new draft (Robert Hanson)
- Re: CIF-JSON new draft (Marcin Wojdyr)
- References:
- CIF-JSON new draft (James Hester)
- Re: CIF-JSON new draft (Marcin Wojdyr)
- RE: CIF-JSON new draft (Bollinger, John C)
- Prev by Date: RE: CIF-JSON new draft
- Next by Date: Re: CIF-JSON new draft
- Prev by thread: RE: CIF-JSON new draft
- Next by thread: Re: CIF-JSON new draft
- Index(es):