Skip to content

Instantly share code, notes, and snippets.

@Willshaw
Created February 4, 2015 12:46
Show Gist options
  • Save Willshaw/2346d72c0dcc0063d23b to your computer and use it in GitHub Desktop.
Save Willshaw/2346d72c0dcc0063d23b to your computer and use it in GitHub Desktop.
<cfscript>
lst = '';
cnt = 10000;
for( i = 1; i <= cnt; i++ ) {
val = randRange( 1, 5 );
lst = listAppend( lst, val );
}
writeOutput( 'list has this many entries: ' & listLen( lst ) & '<br />' );
// convert to distinct array using java
timer = getTickCount();
arrDistinctVals = createObject("java", "java.util.HashSet")
.init( listToArray( lst ) )
.toArray();
writeOutput( 'java took: ' & ( getTickCount() - timer ) & '<br />' );
writeDump( arrDistinctVals );
skv = {};
timer = getTickCount();
for( j = 1; j <= cnt; j++ ) {
skv[ listGetAt( lst, j ) ] = '';
}
writeOutput( 'struct took: ' & ( getTickCount() - timer ) & '<br />' );
arrDistinctVals = listToArray( structKeyList( skv ) );
arraySort( arrDistinctVals, "numeric" );
writeDump( arrDistinctVals );
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment