|
| 1 | +Class isc.zlib.Test Extends %Persistent |
| 2 | +{ |
| 3 | + |
| 4 | +Parameter ZLIBID = 4995; |
| 5 | + |
| 6 | +/// Get path to zlib callout shared library |
| 7 | +/// Library assumed to be in bin folder, unless specified otherwise |
| 8 | +ClassMethod getLibPath() [ CodeMode = expression ] |
| 9 | +{ |
| 10 | +$g(^isc.zlib.Test, $g(^%SYS("bindir")) _ "zlibisc." _ $select($$$isWINDOWS:"dll", 1:"so")) |
| 11 | +} |
| 12 | + |
| 13 | +/// Same callout library, but with immediate loading |
| 14 | +/// do ##class(isc.zlib.Test).callout3() |
| 15 | +ClassMethod callout3(text = "Hello World", rounds As %Integer = 10000) |
| 16 | +{ |
| 17 | + set path = ..getLibPath() |
| 18 | + for i=1:1:rounds{ |
| 19 | + kill out |
| 20 | + set out = $ZF(-3, path, "Compress", text) |
| 21 | + } |
| 22 | + do $ZF(-3, "") |
| 23 | +} |
| 24 | + |
| 25 | +/// Done once per system start, so we don't count it. |
| 26 | +/// do ##class(isc.zlib.Test).callout6Init() |
| 27 | +ClassMethod callout6Init() |
| 28 | +{ |
| 29 | + set sc = $ZF(-4,6,..#ZLIBID) |
| 30 | + set sc = $ZF(-4,5,..#ZLIBID, ..getLibPath()) |
| 31 | +} |
| 32 | + |
| 33 | +/// Callout library, but with system loading |
| 34 | +/// do ##class(isc.zlib.Test).callout6() |
| 35 | +ClassMethod callout6(text = "Hello World", rounds As %Integer = 10000) |
| 36 | +{ |
| 37 | + for i=1:1:rounds{ |
| 38 | + kill out |
| 39 | + set out = $ZF(-6, ..#ZLIBID, 1, text) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +/// Java GateWay implementation |
| 44 | +/// do ##class(isc.zlib.Test).jgw() |
| 45 | +ClassMethod jgw(text = "Hello World", rounds As %Integer = 10000) |
| 46 | +{ |
| 47 | + set gateway = ##class(isc.zlib.Utils).connect() |
| 48 | + for i=1:1:rounds{ |
| 49 | + kill out |
| 50 | + set out = ##class(isc.zlib.Java).compress(gateway, text) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/// Default system implementation |
| 55 | +/// do ##class(isc.zlib.Test).system() |
| 56 | +ClassMethod system(text = "Hello World", rounds As %Integer = 10000) |
| 57 | +{ |
| 58 | + for i=1:1:rounds{ |
| 59 | + kill out |
| 60 | + set out = $extract($SYSTEM.Util.Compress(text), 2, *-1) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +/// NodeJS implementation |
| 65 | +/// do ##class(isc.zlib.Test).node() |
| 66 | +ClassMethod node(text = "Hello World", rounds As %Integer = 10000) |
| 67 | +{ |
| 68 | + set req = ##class(%Net.HttpRequest).%New() |
| 69 | + set req.Server = "localhost" |
| 70 | + set req.Port = 3000 |
| 71 | + set req.Location = "/zlibapi/" _ text |
| 72 | + |
| 73 | + for i=1:1:rounds{ |
| 74 | + kill out |
| 75 | + set sc = req.Get(,,$$$NO) |
| 76 | + set out = req.HttpResponse.Data //.Read($$$MaxStringLength) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +/// textLength - either text, or a number of symbols in text |
| 81 | +/// rounds - number of calls to zlib |
| 82 | +/// do ##class(isc.zlib.Test).test() |
| 83 | +ClassMethod test(textLength As %Integer = 100, rounds As %Integer = 10000) |
| 84 | +{ |
| 85 | + set:textLength="" textLength = 100 |
| 86 | + |
| 87 | + if ($isvalidnum(textLength) && (textLength=$normalize(textLength, 0))) { |
| 88 | + set text = ##class(%PopulateUtils).StringMin(textLength, textLength) |
| 89 | + } else { |
| 90 | + set text = textLength |
| 91 | + set textLength = $l(text) |
| 92 | + } |
| 93 | + |
| 94 | + do ..callout6Init() |
| 95 | + |
| 96 | + write "Text: ", text, ! |
| 97 | + write "Text length: ", $l(text), ! |
| 98 | + write "Rounds: ", rounds, ! |
| 99 | + for method="callout3", "callout6", "system", "jgw", "node" { |
| 100 | + set start = $zh |
| 101 | + do $classmethod(,method, text, rounds) |
| 102 | + set end = $zh |
| 103 | + |
| 104 | + set time = end - start |
| 105 | + |
| 106 | + write "Method: ", method, ! |
| 107 | + write "Time: ", time, ! |
| 108 | + write "Speed (Kb/sec): ", $normalize(textLength*rounds/1024/time, 0), ! |
| 109 | + write "Speed (calls/sec): ", $normalize(rounds/time, 0), ! |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +Storage Default |
| 114 | +{ |
| 115 | +<Data name="TestDefaultData"> |
| 116 | +<Value name="1"> |
| 117 | +<Value>%%CLASSNAME</Value> |
| 118 | +</Value> |
| 119 | +</Data> |
| 120 | +<DataLocation>^isc.zlib.TestD</DataLocation> |
| 121 | +<DefaultData>TestDefaultData</DefaultData> |
| 122 | +<IdLocation>^isc.zlib.TestD</IdLocation> |
| 123 | +<IndexLocation>^isc.zlib.TestI</IndexLocation> |
| 124 | +<StreamLocation>^isc.zlib.TestS</StreamLocation> |
| 125 | +<Type>%Library.CacheStorage</Type> |
| 126 | +} |
| 127 | + |
| 128 | +} |
| 129 | + |
0 commit comments