12.07.2015 Views

Using Caché Globals - InterSystems Documentation

Using Caché Globals - InterSystems Documentation

Using Caché Globals - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ExamplesNote:The globals described in this document should not be confused with another type of <strong>Caché</strong>array variable: process-private globals. Process-private globals are not persistent; they persistonly for the duration of the process that created them. Process-private globals are also notconcurrent; they can only be accessed by the process that created them. A process-privateglobal can be easily distinguished from a global by its multi-character name prefix: either^|| or ^|"^"|.1.2 ExamplesA simple example can demonstrate the ease and performance of globals. The following programexample creates a 10,000–node array (deleting it first if present) and stores it in the database. You cantry this to get a sense of the performance of globals:Creating a Persistent ArraySet start = $ZH // get current timeKill ^Test.GlobalFor i = 1:1:10000 {Set ^Test.Global(i) = i}Set elap = $ZH - start // get elapsed timeWrite "Time (seconds): ",elapWe can also see how long it takes to iterate over and read the values in the array (make sure to run theabove example first to build the array):Reading a Persistent ArraySet start = $ZH // get current timeSet total = 0Set count = 0// get key and value for first nodeSet i = $Order(^Test.Global(""),1,data)While (i '= "") {Set count = count + 1Set total = total + data}// get key and value for next nodeSet i = $Order(^Test.Global(i),1,data)Set elap = $ZH - start // get elapsed timeWrite "Nodes:",count,!Write "Total:",total,!Write "Time (seconds): ",elap,!<strong>Using</strong> <strong>Caché</strong> <strong>Globals</strong> 3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!