Skip to content

Instantly share code, notes, and snippets.

@intsuc
Last active May 18, 2023 12:16
Show Gist options
  • Save intsuc/6a9065f8f6baa2ac693b022086c7016d to your computer and use it in GitHub Desktop.
Save intsuc/6a9065f8f6baa2ac693b022086c7016d to your computer and use it in GitHub Desktop.
data remove storage _ a
data remove storage _ b
function ite
data remove storage _ a
data modify storage _ b set value 0
function ite
data modify storage _ a set value 0
data remove storage _ b
function ite
data modify storage _ a set value 0
data modify storage _ b set value 0
function ite
# `storage _ a` must not mutated here
# if a or b then f else return
# = if a then f else if (not a) and b then f else return
# = if a then f else if not a if b then f else return
# = if a then f else unless a if b then f else return
# = if a then f else unless a if b then f
execute if data storage _ a run function ite-f
execute unless data storage _ a if data storage _ b run function ite-f
data remove storage _ a
data remove storage _ b
function ite_return
data remove storage _ a
data modify storage _ b set value 0
function ite_return
data modify storage _ a set value 0
data remove storage _ b
function ite_return
data modify storage _ a set value 0
data modify storage _ b set value 0
function ite_return
# `storage _ a` must not mutated here
# if a or b then f else return
# = if a then f else (if (not a) and b then f else return)
# = if a then f else (if not a then (if b then f else return) else return)
# = if a then f else (if a then return else (if b then f else return))
# = if a then f else (if a then return else (if b then f))
execute if data storage _ a run function ite_return-f
execute if data storage _ a run return 0
execute if data storage _ b run function ite_return-f
{
"mchVersion": "0.8.1",
"forks": 3,
"jvm": "C:\\graalvm-ee-java19-22.3.1\\bin\\java.exe",
"jvmArgs": [],
"jdkVersion": "19.0.2",
"vmName": "Java HotSpot(TM) 64-Bit Server VM",
"vmVersion": "19.0.2+7-jvmci-22.3-b11",
"mcArgs": [
"nogui"
],
"warmupIterations": 5,
"warmupTime": "3 s",
"measurementIterations": 5,
"measurementTime": "3 s",
"results": [
{
"benchmark": "ite_return-0-0",
"mode": "execute",
"count": 15,
"score": 1718.2176384643037,
"error": 48.474517480521705,
"unit": "ns/op"
},
{
"benchmark": "ite_return-0-1",
"mode": "execute",
"count": 15,
"score": 1827.8519609427972,
"error": 118.42303081370734,
"unit": "ns/op"
},
{
"benchmark": "ite_return-1-0",
"mode": "execute",
"count": 15,
"score": 1801.401209144205,
"error": 145.37703907088564,
"unit": "ns/op"
},
{
"benchmark": "ite_return-1-1",
"mode": "execute",
"count": 15,
"score": 1439.144498123995,
"error": 17.26929098587991,
"unit": "ns/op"
},
{
"benchmark": "ite-0-0",
"mode": "execute",
"count": 15,
"score": 1516.8582392648589,
"error": 48.51049925588024,
"unit": "ns/op"
},
{
"benchmark": "ite-0-1",
"mode": "execute",
"count": 15,
"score": 1649.1604241028047,
"error": 50.03799089225512,
"unit": "ns/op"
},
{
"benchmark": "ite-1-0",
"mode": "execute",
"count": 15,
"score": 1650.549820131366,
"error": 119.58841601794194,
"unit": "ns/op"
},
{
"benchmark": "ite-1-1",
"mode": "execute",
"count": 15,
"score": 1397.1373029492356,
"error": 15.813636299337432,
"unit": "ns/op"
},
{
"benchmark": "min_not_nor-0-0",
"mode": "execute",
"count": 15,
"score": 1911.7531632558264,
"error": 45.49082231903125,
"unit": "ns/op"
},
{
"benchmark": "min_not_nor-0-1",
"mode": "execute",
"count": 15,
"score": 2035.248407497095,
"error": 100.36372917246088,
"unit": "ns/op"
},
{
"benchmark": "min_not_nor-1-0",
"mode": "execute",
"count": 15,
"score": 1962.8085284228791,
"error": 59.149472156250646,
"unit": "ns/op"
},
{
"benchmark": "min_not_nor-1-1",
"mode": "execute",
"count": 15,
"score": 1689.877752567717,
"error": 255.07298840489628,
"unit": "ns/op"
},
{
"benchmark": "min_or-0-0",
"mode": "execute",
"count": 15,
"score": 1812.0777443812483,
"error": 39.868678394166025,
"unit": "ns/op"
},
{
"benchmark": "min_or-0-1",
"mode": "execute",
"count": 15,
"score": 2300.282105684136,
"error": 95.3462489930704,
"unit": "ns/op"
},
{
"benchmark": "min_or-1-0",
"mode": "execute",
"count": 15,
"score": 2276.790083711873,
"error": 64.36931305896725,
"unit": "ns/op"
},
{
"benchmark": "min_or-1-1",
"mode": "execute",
"count": 15,
"score": 2150.9736101731005,
"error": 290.68809777605907,
"unit": "ns/op"
},
{
"benchmark": "not_nor-0-0",
"mode": "execute",
"count": 15,
"score": 1545.2219424012685,
"error": 84.0612039713511,
"unit": "ns/op"
},
{
"benchmark": "not_nor-0-1",
"mode": "execute",
"count": 15,
"score": 1612.358023578586,
"error": 74.59924072492747,
"unit": "ns/op"
},
{
"benchmark": "not_nor-1-0",
"mode": "execute",
"count": 15,
"score": 1429.1411001110796,
"error": 17.523604048804152,
"unit": "ns/op"
},
{
"benchmark": "not_nor-1-1",
"mode": "execute",
"count": 15,
"score": 1159.4863607390155,
"error": 28.7908069765549,
"unit": "ns/op"
}
]
}
data remove storage _ a
data remove storage _ b
function min_not_nor
data remove storage _ a
data modify storage _ b set value 0
function min_not_nor
data modify storage _ a set value 0
data remove storage _ b
function min_not_nor
data modify storage _ a set value 0
data modify storage _ b set value 0
function min_not_nor
# if a or b then f else return
# = unless a or b then return else f
# = unless a unless b then return else f
# = if (unless a unless b then 1 else 0) == 1 then f else return
scoreboard players set _ _ 1
execute unless data storage _ a unless data storage _ b run scoreboard players set _ _ 0
execute if score _ _ matches 1.. run function min_not_nor-f
data remove storage _ a
data remove storage _ b
function min_or
data remove storage _ a
data modify storage _ b set value 0
function min_or
data modify storage _ a set value 0
data remove storage _ b
function min_or
data modify storage _ a set value 0
data modify storage _ b set value 0
function min_or
# if a or b then f else return
# = if ((if a then 1 else 0) min (if b then 1 else 0)) == 1 then f else return
# = if ((if a then 1 else 0) min (if b then 1 else 0)) == 1 then f
scoreboard players set _ _ 0
execute if data storage _ a run scoreboard players set _ _ 1
execute if data storage _ b run scoreboard players set _ _ 1
execute if score _ _ matches 1.. run function min_or-f
data remove storage _ a
data remove storage _ b
function not_nor
data remove storage _ a
data modify storage _ b set value 0
function not_nor
data modify storage _ a set value 0
data remove storage _ b
function not_nor
data modify storage _ a set value 0
data modify storage _ b set value 0
function not_nor
# if a or b then f else return
# = unless a or b then return else f
# = unless a unless b then return else f
execute unless data storage _ a unless data storage _ b run return 0
function not_nor-f
scoreboard players reset *
scoreboard objectives remove _
scoreboard objectives add _ dummy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment