// memorize function
function Memorize(fs) {
var temp_dict = {
fields: Schema(fs)['fields'],
geometryType: '',
features: []
}
for (var f in fs) {
var attrs = {}
for (var attr in f) {
attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
}
Push(
temp_dict['features'],
{attributes: attrs}
)
}
return FeatureSet(Text(temp_dict))
}
// output dictionary
var out_dict = {
fields: [
{name: 'step', type: 'esriFieldTypeInteger'},
{name: 'duration', type: 'esriFieldTypeInteger'},
{name: 'method', type: 'esriFieldTypeString'}
],
geometryType: '',
features: []
}
// start step count, timer
var i = 0
var start = Now()
Push(
out_dict['features'],
{
attributes: {
step: i,
duration: DateDiff(Now(), start),
method: 'Traditional'
}
}
)
// states and counties
var states = FeatureSetByPortalItem(
Portal('https://arcgis.com'),
'8c2d6d7df8fa4142b0a1211c8dd66903',
0,
['STATE_FIPS', 'POPULATION'],
false
)
var counties = FeatureSetByPortalItem(
Portal('https://arcgis.com'),
'3c164274a80748dda926a046525da610',
0,
['NAME', 'STATE_FIPS', 'POPULATION'],
false
)
// loop through counties
for (var c in counties) {
// get parent state feature
var the_state = First(Filter(states, `STATE_FIPS = '${c['STATE_FIPS']}'`))
Push(
out_dict['features'],
{
attributes: {
step: i,
duration: DateDiff(Now(), start),
method: 'Traditional'
}
}
)
i ++
}
// reset counter for memorized version
// start step count, timer
i = 0
start = Now()
Push(
out_dict['features'],
{
attributes: {
step: i,
duration: DateDiff(Now(), start),
method: 'Memorized'
}
}
)
// states and counties
var memstates = Memorize(FeatureSetByPortalItem(
Portal('https://arcgis.com'),
'8c2d6d7df8fa4142b0a1211c8dd66903',
0,
['STATE_FIPS', 'POPULATION'],
false
))
var memcounties = Memorize(FeatureSetByPortalItem(
Portal('https://arcgis.com'),
'3c164274a80748dda926a046525da610',
0,
['NAME', 'STATE_FIPS', 'POPULATION'],
false
))
// loop through counties
for (var c in memcounties) {
// get parent state feature
var the_state = First(Filter(memstates, `STATE_FIPS = '${c['STATE_FIPS']}'`))
Push(
out_dict['features'],
{
attributes: {
step: i,
duration: DateDiff(Now(), start),
method: 'Memorized'
}
}
)
i ++
}
return FeatureSet(Text(out_dict))