Skip to content

Instantly share code, notes, and snippets.

@intsuc
intsuc / .md
Created October 14, 2022 09:52
Benchmark Score Error Unit
and32_00000000 128769.63327197109 ± 2114.7849582880303 ns/op
and32_ffffffff 120241.9137528857 ± 6488.60990017952 ns/op
Benchmark Score Error Unit
and_if_00000000_00000000 22391.759096515496 ± 558.0100288017094 ns/op
and_if_ffffffff_00000000 26100.25960443618 ± 25.73106624882582 ns/op
and_if_ffffffff_ffffffff 38305.73820596604 ± 246.7094792231368 ns/op
and_mul_00000000_00000000 55313.342677146815 ± 1715.6443799125116 ns/op
and_mul_ffffffff_00000000 58899.62210323747 ± 394.43693944134094 ns/op
and_mul_ffffffff_ffffffff 53902.02468743612 ± 507.7308772062884 ns/op
@intsuc
intsuc / example.mcfunction
Last active April 6, 2022 11:30
Prints an integer using terminal sequences
function print_init/init
scoreboard players set int _ -1234567890
function print_int/
data modify storage _ c set from storage _ b
# `_ a` is copied once.
execute store result score result _ run data modify storage _ c set from storage _ a
data remove storage _ c
@intsuc
intsuc / b.mcfunction
Last active March 22, 2022 12:23
Benchmark results of list-mapped trie
execute store result score a a if data storage a b[]
execute if score a a matches 0 run data modify storage a b append from storage a a[]
execute if score b a matches 0.. if score a a matches 3 run data remove storage a b[2]
execute if score b a matches ..-1 if score a a matches 2 run data modify storage a b append value []
scoreboard players operation b a += b a
execute store result score a a if data storage a b[-2][]
execute if score a a matches 0 run data modify storage a b[-2] append from storage a a[]
execute if score b a matches 0.. if score a a matches 3 run data remove storage a b[-2][2]
execute if score b a matches ..-1 if score a a matches 2 run data modify storage a b[-2] append value []
@intsuc
intsuc / .md
Created February 23, 2022 14:15
Comparison on memory footprint of numeric collections

Comparison on memory footprint of numeric collections

Details

# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit shift.
# WARNING | Compressed references base/shifts are guessed by the experiment!
# WARNING | Therefore, computed addresses are just guesses, and ARE NOT RELIABLE.
@intsuc
intsuc / init.mcfunction
Created January 16, 2022 10:53
float_to_int_bits
scoreboard objectives remove _
scoreboard objectives add _ dummy
scoreboard players set -1 _ -1
scoreboard players set 2¹ _ 2
scoreboard players set 2² _ 4
scoreboard players set 2³ _ 8
scoreboard players set 2⁴ _ 16
scoreboard players set 2⁵ _ 32
scoreboard players set 2⁶ _ 64
@intsuc
intsuc / init.mcfunction
Last active January 14, 2022 15:53
int_bits_to_float
scoreboard objectives remove _
scoreboard objectives add _ dummy
scoreboard players set -2³¹ _ -2147483648
scoreboard players set 2² _ 4
scoreboard players set 2³ _ 8
scoreboard players set 2⁴ _ 16
scoreboard players set 2⁵ _ 32
scoreboard players set 2⁶ _ 64
scoreboard players set 2⁷ _ 128
@intsuc
intsuc / LICENSE
Last active January 1, 2024 01:08
All my gists (https://gist.github.com/intsuc) are under the following license
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@intsuc
intsuc / example.mcfunction
Last active January 10, 2022 11:55
An indexable NBT structure with two-level cache
function init
scoreboard players set index _ 0
function load
tellraw @s {"nbt": "_[0][0]", "storage": "_"}
function load
tellraw @s {"nbt": "_[0][0]", "storage": "_"}
scoreboard players set index _ 1