Skip to content

Instantly share code, notes, and snippets.

@zonca
Created April 23, 2025 21:52
Show Gist options
  • Save zonca/20d0b571a03be660571f4a125854c066 to your computer and use it in GitHub Desktop.
Save zonca/20d0b571a03be660571f4a125854c066 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Architecture: x86_64\n",
"CPU op-mode(s): 32-bit, 64-bit\n",
"Byte Order: Little Endian\n",
"CPU(s): 48\n",
"On-line CPU(s) list: 0-47\n",
"Thread(s) per core: 1\n",
"Core(s) per socket: 24\n",
"Socket(s): 2\n",
"NUMA node(s): 2\n",
"Vendor ID: GenuineIntel\n",
"CPU family: 6\n",
"Model: 85\n",
"Model name: Intel(R) Xeon(R) Platinum 8168 CPU @ 2.70GHz\n",
"Stepping: 4\n",
"CPU MHz: 1199.871\n",
"CPU max MHz: 3700.0000\n",
"CPU min MHz: 1200.0000\n",
"BogoMIPS: 5400.00\n",
"Virtualization: VT-x\n",
"L1d cache: 32K\n",
"L1i cache: 32K\n",
"L2 cache: 1024K\n",
"L3 cache: 33792K\n",
"NUMA node0 CPU(s): 0-23\n",
"NUMA node1 CPU(s): 24-47\n",
"Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_pt ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke spec_ctrl intel_stibp flush_l1d\n"
]
}
],
"source": [
"!lscpu"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import healpy as hp\n",
"import numpy as np\n",
"import astropy.units as u\n",
"import os\n",
"import astropy"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import timeit\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def to_time(s):\n",
" return (t.average * u.s).round(decimals=2).to_value(u.s)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from astropy.table import QTable"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1min 59s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n",
"8min 16s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n",
"17.3 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n",
"1min 8s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n",
"7.49 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n",
"13.8 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
]
}
],
"source": [
"#table = []\n",
"for nside in [8192]:\n",
" lmax = min(3*nside-1, 2*8192)\n",
"\n",
" alm_size = hp.Alm.getsize(lmax=lmax)\n",
"\n",
" npix = hp.nside2npix(nside)\n",
"\n",
" m = np.ones(npix, dtype=np.double)\n",
"\n",
"\n",
" record = {\"nside\":nside, \"npix\":npix, \"alm_size\":alm_size, \"lmax\":lmax}\n",
"\n",
" t = %timeit -n 1 -r 1 -o hp.map2alm(m, lmax=lmax, use_pixel_weights=nside < 8192)\n",
" record[\"map2alm_I\"] = to_time(t)\n",
"\n",
" t = %timeit -n 1 -r 1 -o hp.map2alm([m,m,m], lmax=lmax, use_pixel_weights=nside < 8192)\n",
" record[\"map2alm_IQU\"] = to_time(t)\n",
"\n",
" alm = hp.map2alm(m, lmax=lmax, use_pixel_weights=nside < 8192)\n",
"\n",
" t = %timeit -n 1 -r 1 -o hp.alm2map(alm, lmax=lmax, nside=nside, verbose=False)\n",
" record[\"alm2map_I\"] = to_time(t)\n",
"\n",
" t = %timeit -n 1 -r 1 -o hp.alm2map([alm, alm, alm], lmax=lmax, nside=nside, verbose=False)\n",
" record[\"alm2map_IQU\"] = to_time(t)\n",
"\n",
" hp.write_map(\"m.fits\", [m, m, m], overwrite=True)\n",
"\n",
" hp.write_alm(\"alm.fits\", [alm, alm, alm], overwrite=True)\n",
"\n",
" record[\"IQU_map_filesize\"] = astropy.utils.console.human_file_size(os.path.getsize(\"m.fits\"))\n",
"\n",
" record[\"IQU_alm_filesize\"] = astropy.utils.console.human_file_size(os.path.getsize(\"alm.fits\"))\n",
"\n",
" t = %timeit -n 1 -r 1 -o hp.read_map(\"m.fits\", verbose=False)\n",
" record[\"read_map_IQU\"] = to_time(t)\n",
"\n",
" t = %timeit -n 1 -r 1 -o hp.read_alm(\"alm.fits\")\n",
" record[\"read_alm_IQU\"] = to_time(t)\n",
"\n",
" table.append(record)\n",
" pd.DataFrame(table).set_index(\"nside\").to_csv(\"benchmark_healpy_operations.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment