Platform
Resources
Pricing
Sign in
Contact us
Fil
Vocateur.
Workspace
Fork
Published
2 collections
By
Fil
Edited
Sep 13, 2021
3 stars
Meta
prefixVarsInFormula
Discrete distribution input
height
iframe test
Fenced code highlighter
What's this?
Fullscreen
SVG editing
Editable SVG
File Uploader
pt - pretty-print matrices & tensors
selectFlat input
Hello html2canvas
GeoJSON feature editor
width
Testing visibility continuously
Force Simulation Web Worker
math
Hello SharedArrayBuffer
Prettier Observable Bookmarklet
D3 Projections
Fullwidth Observable Bookmarklet
Invalidation
Hello iocane
Drag to re-arrange
Signature
Hello JSON-editor
Worker
d3.csv code snippet
Format Comma-Separated Tree
Layers Perspective
My Notebooks
Cool Observable Notebooks
Cool Notebooks Circle
Also listed in…
Hello
Insert cell
Insert cell
sharedBuffer
=
new
SharedArrayBuffer
(
Int32Array
.
BYTES_PER_ELEMENT
*
1e7
)
// 4 bytes per item in a Float32Array
Insert cell
import
{
worker
}
from
"@fil/worker"
Insert cell
Insert cell
C
=
navigator
.
hardwareConcurrency
||
4
Insert cell
runWorkers
=
{
launchWorkers
;
const
seed
=
Math
.
random
(
)
,
time
=
performance
.
now
(
)
;
await
Promise
.
all
(
Array
.
from
(
{
length
:
C
}
,
(
_
,
start
)
=>
new
Promise
(
notify
=>
worker
(
compute
,
{
seed
,
sharedBuffer
,
start
,
n
:
1000
,
C
}
)
(
notify
)
)
)
)
;
return
performance
.
now
(
)
-
time
;
}
Insert cell
(
runWorkers
,
new
Float32Array
(
sharedBuffer
)
)
Insert cell
function
compute
(
options
)
{
const
sharedArray
=
new
Float32Array
(
options
.
sharedBuffer
)
,
n
=
options
.
n
||
1000
,
C
=
navigator
.
hardwareConcurrency
||
4
;
for
(
let
i
=
options
.
start
;
i
<
sharedArray
.
length
;
i
+=
C
)
{
for
(
let
a
=
0
;
a
<
n
;
a
++
// make it slow :D
)
sharedArray
[
i
]
=
Math
.
cos
(
i
/
100
+
options
.
seed
)
;
}
return
"anything"
;
// a message saying we're done
}
Insert cell
Insert cell
Insert cell
normal
=
{
if
(
!
launchNormal
)
return
;
const
seed
=
Math
.
random
(
)
,
time
=
performance
.
now
(
)
;
for
(
let
start
=
0
;
start
<
C
;
start
++
)
compute
(
{
seed
,
sharedBuffer
,
start
,
n
:
1000
,
C
}
)
;
return
performance
.
now
(
)
-
time
;
}
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Listed in...
Meta
Fil
Hello
Fil
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sharedBuffer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
launchWorkers
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
C
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
runWorkers
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
compute
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
launchNormal
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
normal
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML