Reply to topic  [ 15 posts ] 
Fast retrieving from an array how? 
Author Message

Joined: 2007-04-12 14:59:36
Posts: 229
I have a numbered list of a thousand words. A macro getting a sample word from a file should check whether the sample word is in the list, and if yes, retrieve its index number.
For starters I had put my list in a file (1 Adam, 2 Eve, 3 Moses etc.) and had the macro open that file, search the sample word, find the index number in front of it and pass it on to the rest of the macro.
To get the macro work faster, I then put the list on an array, using the text.split function and retrieving the number with array.indexOfValue. This works all fine, but it is hardly faster than the clumsy method I use before, several seconds just to get the index number. Can this be improved?


2010-09-09 03:12:24
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
js wrote:
Can this be improved?
Generally speaking you can speed up that kind of macros by treating strings as plain text (not attributed text) and, presumably, by using a hash instead of an array. If you need something more specific, post your macro with sample documents. It is impossible to know how your macro is coded from your words. Or is it copyrighted? ;-)


2010-09-09 05:07:19
Profile

Joined: 2007-04-12 14:59:36
Posts: 229
This is my shortened code. The original word list is in Chinese. I don't know if the handling of two-byte characters is good for a further delay?

Code:
$pickup = read selection
$mylist = 'Adam, Eve, Moses, AndAThousandOthers'
$mylistArr = $mylist.split(', ')
$indexNr = $mylistArr.indexOfValue $pickup
$indexNr += 1
prompt "$indexNr"


2010-09-09 05:28:52
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
What is the real code of this?
Quote:
$mylist = 'Adam, Eve, Moses, AndAThousandOthers'
I.e. how does your macro get words from the word list file and does it construct $mylist? I’m almost certain that the culprit of the slowness is that part of your macro. Post the whole code without omitting anything.

Quote:
The original word list is in Chinese. I don't know if the handling of two-byte characters is good for a further delay?
There is no problem. Post the first 50 words or so without modifying anything. The format does matter. One important thing: is the file format is RTF or Plain Text file?

BTW “two-byte character” is obsolete. All Chinese characters consist of three or more bytes in UTF-8.


2010-09-09 05:47:36
Profile

Joined: 2007-04-12 14:59:36
Posts: 229
Here you are. I cut the list after about 130 items.
The full list of 1000 items is in the macro itself. The input is a selected word in any Nisus .rtf file. I want to know it's place in the list (i.e. to get the $indexNr which I need to know to locate the word later on elsewhere, within a context that it defined by that number).

Code:
$pickup = read selection
$mylist = '言, 語, 謂, 訪, 請, 召, 報, 告, 諫, 討, 反, 復, 舍, 次, 如, 馳, 驟, 侵, 襲, 奔, 亡, 逐, 及, 執, 免, 享, 薦, 圖, 虞, 克, 堪, 有, 無, 昭, 穆, 勤, 乏, 亂, 整, 兩, 貳, 兵, 車, 甲, 介, 卒, 乘, 君, 師, 姑, 女, 族, 黨, 讎, 河, 防, 城, 池, 田, 館, 辭, 謝, 責, 讓, 爭, 使, 令, 屬, 托, 往, 來, 去, 從, 違, 即, 就, 趨, 赴, 戰, 擊, 引, 卻, 馮, 據, 約, 解, 釋, 具, 給, 計, 謀, 會, 習, 疾, 病, 餓, 厭, 衰, 崩, 匱, 困, 侈, 靡, 寡, 少, 微, 強, 固, 再, 三, 帝, 後, 王, 侯, 子, 息, 宗, 廟, 詩, 書, 禮, 樂, 知, 識, 見, 示, 視'
$mylistArr = $mylist.split(', ')
$indexNr = $mylistArr.indexOfValue $pickup
$indexNr += 1
if $indexNr == 0
exit "\“$pickup\“ not in the list"
end
prompt $indexNr


2010-09-09 06:57:00
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
That’s strange. I replaced the content of $mylist with 2500 Chinese characters extracted from someone’s book and the macro works immediately. I have not noticed any delay so I cannot tell what is wrong with the code. Anyway, try to put Cast to String which removes style attributes from the data and/or select the whole paragraph beginning with $mylist and apply :Format:Remove Attributes and Styles on it.
Code:
$mylist = Cast to String '言, 語, 謂, 訪, 請, 召, 報, 告, 諫, 討, 反, 復, 舍, 次, 如, 馳, 驟, 侵, 襲, 奔, 亡, 逐, 及, 執, 免, 享, 薦, 圖, 虞, 克, 堪, 有, 無, 昭, 穆, 勤, 乏, 亂, 整, 兩, 貳, 兵, 車, 甲, 介, 卒, 乘, 君, 師, 姑, 女, 族, 黨, 讎, 河, 防, 城, 池, 田, 館, 辭, 謝, 責, 讓, 爭, 使, 令, 屬, 托, 往, 來, 去, 從, 違, 即, 就, 趨, 赴, 戰, 擊, 引, 卻, 馮, 據, 約, 解, 釋, 具, 給, 計, 謀, 會, 習, 疾, 病, 餓, 厭, 衰, 崩, 匱, 困, 侈, 靡, 寡, 少, 微, 強, 固, 再, 三, 帝, 後, 王, 侯, 子, 息, 宗, 廟, 詩, 書, 禮, 樂, 知, 識, 見, 示, 視'

Also put Debug.setCodeProfilingEnabled true at the beginning of the macro. This fantastic command is very useful when you want to improve the performance of a macro.

Edit: added an instruction about :Format:Remove Attributes and Styles.
Edit: corrected a typo.


2010-09-09 07:20:30
Profile

Joined: 2007-04-12 14:59:36
Posts: 229
Thank you for trying to help.For the moment I can't see a noticeable difference. Of course the macro is still working, but I thought there would be a big difference with or without file opening.


2010-09-09 08:59:11
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Did you try the code profiling command Kino gave? It can often reveal unexpected performance drains. Otherwise, why don't you post your full macro file as a forum attachment (or send it to me privately if you prefer), so we can take a look. Thanks.


2010-09-09 10:30:43
Profile WWW

Joined: 2007-04-12 14:59:36
Posts: 229
Martin,

Sorry to reply late.
I added the line Debug.setCodeProfilingEnabled true, as suggested by Kino. I also applied „Remove Attributes & Styles“ to the macro Then I executed the macro exactly as indicated above, just without the last line that prom before executing. As a search word, I selected the last character in myList of the macro itself. So all the macro had to do was finding that that last item was item nr 127 of the list myList. For this I got the following result:

Total macro elapsed time: 0.6 seconds
Total profiled execution time: 0.1 seconds

Doing the same thing but with the complete list of 1086 characters, the results were as follows:
Total macro elapsed time: 1.4 seconds
Total profiled execution time: 0.9 seconds

In others words, the macro takes roughly 1 second to count a thousand items. Please tell me if this is sounds like a reasonable amount of time to you. I thought macros can do this kind of thing much faster and that maybe there was better code than the one I was able to write.


2010-09-15 12:33:49
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
I wouldn't expect a macro to take that long to search an array of 1000+ items. But Kino's recommendation to turn on debug profiling wasn't to time the macro, but instead to see where that time is being spent. After the macro completes, you should see a debug profile document that shows percentages for each line of code; what part of your macro takes the longest? You may find that the search is almost instantaneous, but perhaps building the array is what takes a long time?

Can you attach your full macro file to this thread?


2010-09-15 13:14:57
Profile WWW

Joined: 2007-04-12 14:59:36
Posts: 229
Here you are.
It seems that (without a prompt) 100 % of the time is taken to split the list into it's items.
Code:
# Find selected char in myList
Debug.setCodeProfilingEnabled true
$pickup = read selection
cast to string $pickup
$mylist = '言, 語, 謂, 訪, 請, 召, 報, 告, 諫, 討, 反, 復, 舍, 次, 如, 馳, 驟, 侵, 襲, 奔, 亡, 逐, 及, 執, 免, 享, 薦, 圖, 虞, 克, 堪, 有, 無, 昭, 穆, 勤, 乏, 亂, 整, 兩, 貳, 兵, 車, 甲, 介, 卒, 乘, 君, 師, 姑, 女, 族, 黨, 讎, 河, 防, 城, 池, 田, 館, 辭, 謝, 責, 讓, 爭, 使, 令, 屬, 托, 往, 來, 去, 從, 違, 即, 就, 趨, 赴, 戰, 擊, 引, 卻, 馮, 據, 約, 解, 釋, 具, 給, 計, 謀, 會, 習, 疾, 病, 餓, 厭, 衰, 崩, 匱, 困, 侈, 靡, 寡, 少, 微, 強, 固, 再, 三, 帝, 後, 王, 侯, 子, 息, 宗, 廟, 詩, 書, 禮, 樂, 知, 識, 見, 示, 視, 觀, 望, 矜, 哀, 卹, 憾, 恕, 憤, 患, 持, 措, 拱, 攻, 竊, 誅, 翦, 修, 講, 設, 立, 忠, 信, 諒, 正, 邪, 辟, 好, 惡, 恭, 敬, 慎, 苟, 顯, 著, 相, 帥, 士, 僕, 御, 右, 盜, 賊, 國, 家, 杜, 稷, 仁, 義, 道, 德, 文, 質, 色, 臭, 先, 前, 后, 內, 外, 間, 行, 走, 出, 入, 之, 適, 進, 退, 逾, 逸, 逼, 決, 治, 樹, 藝, 事, 畜, 保, 愛, 傷, 害, 比, 喻, 誠, 偽, 善, 淫, 凶, 疏, 戚, 飢, 孰, 滋, 烈, 贍, 共, 同, 殊, 異, 斤, 鈞, 锺, 倍, 政, 教, 法, 術, 勢, 數, 朝, 野, 塗, 江, 關, 宮, 府, 衣, 冠, 屨, 商, 賈, 旅, 徒, 年, 歲, 說, 聽, 毀, 譽, 勸, 居, 登, 臨, 過, 稱, 量, 鬻, 市, 假, 離, 合, 因, 改, 作, 為, 取, 求, 奉, 致, 得, 益, 竭, 堅, 利, 完, 備, 陳, 故, 窮, 難, 夷, 平, 庸, 已, 必, 一, 參, 什, 伯, 晦, 朔, 時, 世, 期, 官, 吏, 爵, 權, 衡, 果, 實, 聰, 明, 功, 名, 北, 中, 下, 遵, 徂, 徵, 歸, 陟, 降, 流, 放, 游, 浮, 集, 采, 叔, 振, 援, 操, 秉, 舉, 斯, 伐, 稼, 穡, 獲, 納, 交, 錯, 被, 任, 負, 施, 用, 制, 貽, 懷, 慕, 懲, 悼, 淑, 幸, 偷, 薄, 險, 阻, 悠, 皇, 永, 孔, 亟, 庶, 裘, 褐, 裳, 庭, 宇, 畝, 所, 驂, 駟, 策, 矢, 躬, 身, 領, 武, 仇, 耦, 徵, 收, 發, 封, 棄, 俟, 遷, 徙, 遺, 失, 存, 處, 坐, 遇, 接, 承, 扶, 刺, 折, 戮, 問, 對, 許, 省, 審, 慮, 怨, 忍, 快, 興, 廢, 變, 曲, 直, 長, 小, 貪, 廉, 輕, 重, 狂, 殆, 危, 面, 口, 齒, 耳, 目, 指, 飯, 食, 服, 飾, 布, 鬥, 式, 檢, 英, 靈, 豪, 然, 且, 或, 曾, 更, 漸, 俱, 並, 而, 若, 爾, 建, 置, 罷, 學, 養, 乾, 謁, 徇, 矯, 效, 留, 遣, 逢, 候, 延, 勝, 敗, 守, 破, 騎, 伏, 圍, 突, 禽, 縱, 購, 抑, 按, 拔, 擢, 挾, 將, 烝, 亨, 顧, 察, 裁, 斷, 奏, 敕, 委, 捐, 詳, 詐, 與, 奪, 至, 止, 寤, 寐, 恨, 驚, 冀, 貴, 賤, 壯, 大, 多, 篤, 專, 壹, 稍, 略, 輒, 猶, 陰, 陽, 休, 咎, 機, 要, 祖, 賓, 郎, 男, 部, 曹, 鄰, 里, 獄, 闕, 祠, 第, 屏, 帳, 壁, 案, 字, 書, 項, 乳, 體, 意, 諂, 諛, 誣, 辯, 訴, 憐, 閔, 吊, 除, 拜, 營, 務, 積, 聚, 尋, 迭, 代, 替, 成, 遂, 系, 累, 羈, 係, 牽, 縣, 結, 絕, 擅, 披, 拉, 姦, 回, 雅, 俗, 公, 私, 偏, 全, 獨, 特, 醜, 陋, 穢, 玄, 素, 白, 方, 夙, 惟, 霄, 漢, 景, 曜, 都, 邑, 鄙, 邊, 塞, 殷, 周, 胡, 虜, 戎, 倡, 優, 伎, 皁, 宦, 豎, 臧, 獲, 祿, 位, 產, 業, 貨, 賂, 資, 財, 賄, 性, 情, 聲, 響, 拳, 腳, 端, 緒, 節, 度, 議, 論, 諷, 貶, 謫, 斥, 宣, 褒, 贈, 顛, 覆, 率, 詣, 歷, 寓, 寄, 禁, 戒, 恃, 玩, 肆, 敷, 化, 加, 損, 刻, 勒, 鬱, 舒, 張, 弛, 是, 非, 能, 可, 以, 凡, 聖, 殘, 暴, 甘, 辛, 鮮, 敝, 寒, 溫, 幽, 冥, 奧, 精, 眾, 便, 嘉, 遽, 速, 彌, 愈, 尤, 極, 甚, 最, 夫, 婦, 嬰, 孩, 親, 眷, 竹, 木, 穀, 壑, 亭, 臺, 郊, 墟, 材, 才, 簿, 籍, 狀, 類, 壽, 命, 志, 趣, 涕, 泣, 膏, 澤, 帷, 蓋, 梗, 概, 本, 末, 紀, 載, 監, 撫, 游, 揚, 抗, 奮, 沈, 沒, 通, 達, 辨, 析, 判, 切, 推, 移, 革, 聞, 宿, 隨, 沮, 擬, 測, 當, 須, 饒, 秀, 麗, 工, 博, 核, 奇, 偶, 丹, 紅, 允, 舛, 寧, 豫, 尚, 攸, 甫, 聊, 匪, 厥, 經, 典, 簡, 篇, 詞, 賦, 序, 銘, 誄, 贊, 章, 表, 旨, 風, 騷, 翰, 藻, 韻, 律, 榮, 華, 軌, 範, 規, 則, 準, 昆, 弟, 形, 跡, 綺, 練, 倫, 常, 網, 維, 契, 幾, 始, 終, 羞, 辱, 創, 造, 潛, 藏, 步, 履, 枕, 藉, 凌, 厲, 脅, 迫, 隕, 落, 運, 輸, 徭, 役, 戍, 募, 吹, 唱, 叩, 彈, 讀, 啼, 號, 訊, 詰, 敘, 訴, 摹, 寫, 排, 攘, 竄, 列, 垂, 尊, 盛, 虛, 枉, 和, 順, 凜, 凝, 爛, 漫, 赤, 碧, 青, 蒼, 乍, 暫, 每, 既, 卿, 傅, 儀, 容, 祥, 殃, 條, 理, 支, 葉, 朵, 穎, 軒, 冕, 庾, 廩, 帛, 縷, 扃, 牖, 楹, 檻, 梁, 陵, 津, 浦, 疇, 陌, 晡, 曛, 塊, 礫, 掇, 控, 捫, 把, 挑, 搔, 投, 擲, 遞, 蹈, 躡, 升, 緣, 偃, 僕, 斃, 傾, 聆, 眺, 睇, 眄, 瞻, 回, 還, 逝, 分, 訣, 悸, 慟, 悵, 慨, 警, 惕, 欲, 感, 酌, 酹, 酣, 覺, 央, 闌, 清, 澄, 渾, 安, 閑, 乖, 互, 繁, 煩, 急, 忽, 但, 星, 辰, 岳, 丘, 嶺, 棧, 閣, 甸, 藩, 苑, 隴, 塹, 墳, 蹊, 徑, 汀, 洲, 渚, 皋, 涯, 塘, 垠, 輦, 轂, 轅, 轍, 簪, 纓, 紱, 綬, 衾, 襦, 袂, 羹, 飧, 絲, 管, 弦, 鼓, 鼙, 僚, 群, 輩, 思, 索, 鑒, 賞, 料, 想, 占, 卜, 戲, 弄, 動, 定, 駐, 住, 依, 倚, 雕, 製, 生, 消, 淹, 漏, 泛, 涵, 蒙, 蔽, 蔭, 炙, 啖, 餉, 斂, 貢, 激, 濯, 拂, 逆, 凋, 零, 屠, 滅, 罄, 盡, 了, 肖, 暨, 逮, 暝, 黯, 纖, 悉, 贏, 短, 驕, 慢, 妄, 層, 喬, 耿, 渺, 縟, 稠, 綜, 雜, 徧, 塵, 靄, 巒, 岩, 阿, 隅, 畔, 際, 綸, 纂, 床, 蓐, 妝, 匳, 廚, 筵, 肌, 膚'
$mylistArr = $mylist.split(', ')
$indexNr = $mylistArr.indexOfValue $pickup
$indexNr += 1
if $indexNr == 0
exit "\“$pickup\“ not in the list"
end
#prompt $indexNr


2010-09-15 14:19:32
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
js wrote:
It seems that (without a prompt) 100 % of the time is taken to split the list into it's items.

Aha! Well, now we know the inefficiency, let's look at how to avoid it.

The unexpected time taken to split the text has to do with the rich content allowed in any text variable. Basically a split creates a ton of mini content storages that could hold anything, from a single character to graphics, footnotes, etc. Perhaps you can see why that could be expensive.

The easiest way around this is to just make sure your list is plain text before you split it, eg:
Code:
$mylist = Cast to String '言 ...'
$mylistArr = $mylist.split(', ')

Looping the original macro 1000 times takes my machine 25 seconds. After casting the list to a string, the same 1000 times takes 4 seconds. A single run with code profiling disabled is basically instantaneous. Let me know how your running time compares.

All the same, perhaps we can speed up the split command, even for more complex texts.


2010-09-15 14:43:53
Profile WWW

Joined: 2007-04-12 14:59:36
Posts: 229
Thank you. That's it. With a list of thousand I get now this feeling of a quasi-instantaneous process which I expected.
I would be curious enough though to learn how one could improve this for a very long list.


2010-09-16 03:06:32
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
martin wrote:
After casting the list to a string, the same 1000 times takes 4 seconds.

Perhaps did you exclude from the loop Read Selection which seems to be slow? And/or oh! are you running an ultra-fast i5/i7 Mac?!?

Anyway the macro below takes 2 seconds on my Mac mini 2 GHz when running it 1000 times with ‘膚’ (the last item in the array) selected. I don’t know if treating characters not as texts but as numerical values would make a significant difference but this trick enables you to get rid of Cast to String and split commands.
Code:
 Debug.setCodeProfilingEnabled true

$doc = Document.active
if $doc == undefined
   exit
end

$j = 1000  # for testing
while $j  # for testing

$list = Array.new (0x8A00, 0x8A9E, 0x8B02, 0x8A2A, 0x8ACB, 0x53EC, 0x5831, 0x544A, 0x8AEB, 0x8A0E, 0x53CD, 0x5FA9, 0x820D, 0x6B21, 0x5982, 0x99B3, 0x9A5F, 0x4FB5, 0x8972, 0x5954, 0x4EA1, 0x9010, 0x53CA, 0x57F7, 0x514D, 0x4EAB, 0x85A6, 0x5716, 0x865E, 0x514B, 0x582A, 0x6709, 0x7121, 0x662D, 0x7A46, 0x52E4, 0x4E4F, 0x4E82, 0x6574, 0x5169, 0x8CB3, 0x5175, 0x8ECA, 0x7532, 0x4ECB, 0x5352, 0x4E58, 0x541B, 0x5E2B, 0x59D1, 0x5973, 0x65CF, 0x9EE8, 0x8B8E, 0x6CB3, 0x9632, 0x57CE, 0x6C60, 0x7530, 0x9928, 0x8FAD, 0x8B1D, 0x8CAC, 0x8B93, 0x722D, 0x4F7F, 0x4EE4, 0x5C6C, 0x6258, 0x5F80, 0x4F86, 0x53BB, 0x5F9E, 0x9055, 0x5373, 0x5C31, 0x8DA8, 0x8D74, 0x6230, 0x64CA, 0x5F15, 0x537B, 0x99AE, 0x64DA, 0x7D04, 0x89E3, 0x91CB, 0x5177, 0x7D66, 0x8A08, 0x8B00, 0x6703, 0x7FD2, 0x75BE, 0x75C5, 0x9913, 0x53AD, 0x8870, 0x5D29, 0x5331, 0x56F0, 0x4F88, 0x9761, 0x5BE1, 0x5C11, 0x5FAE, 0x5F37, 0x56FA, 0x518D, 0x4E09, 0x5E1D, 0x5F8C, 0x738B, 0x4FAF, 0x5B50, 0x606F, 0x5B97, 0x5EDF, 0x8A69, 0x66F8, 0x79AE, 0x6A02, 0x77E5, 0x8B58, 0x898B, 0x793A, 0x8996, 0x89C0, 0x671B, 0x77DC, 0x54C0, 0x5379, 0x61BE, 0x6055, 0x61A4, 0x60A3, 0x6301, 0x63AA, 0x62F1, 0x653B, 0x7ACA, 0x8A85, 0x7FE6, 0x4FEE, 0x8B1B, 0x8A2D, 0x7ACB, 0x5FE0, 0x4FE1, 0x8AD2, 0x6B63, 0x90AA, 0x8F9F, 0x597D, 0x60E1, 0x606D, 0x656C, 0x614E, 0x82DF, 0x986F, 0x8457, 0x76F8, 0x5E25, 0x58EB, 0x50D5, 0x5FA1, 0x53F3, 0x76DC, 0x8CCA, 0x570B, 0x5BB6, 0x675C, 0x7A37, 0x4EC1, 0x7FA9, 0x9053, 0x5FB7, 0x6587, 0x8CEA, 0x8272, 0x81ED, 0x5148, 0x524D, 0x540E, 0x5167, 0x5916, 0x9593, 0x884C, 0x8D70, 0x51FA, 0x5165, 0x4E4B, 0x9069, 0x9032, 0x9000, 0x903E, 0x9038, 0x903C, 0x6C7A, 0x6CBB, 0x6A39, 0x85DD, 0x4E8B, 0x755C, 0x4FDD, 0x611B, 0x50B7, 0x5BB3, 0x6BD4, 0x55BB, 0x8AA0, 0x507D, 0x5584, 0x6DEB, 0x51F6, 0x758F, 0x621A, 0x98E2, 0x5B70, 0x6ECB, 0x70C8, 0x8D0D, 0x5171, 0x540C, 0x6B8A, 0x7570, 0x65A4, 0x921E, 0x953A, 0x500D, 0x653F, 0x6559, 0x6CD5, 0x8853, 0x52E2, 0x6578, 0x671D, 0x91CE, 0x5857, 0x6C5F, 0x95DC, 0x5BAE, 0x5E9C, 0x8863, 0x51A0, 0x5C68, 0x5546, 0x8CC8, 0x65C5, 0x5F92, 0x5E74, 0x6B72, 0x8AAA, 0x807D, 0x6BC0, 0x8B7D, 0x52F8, 0x5C45, 0x767B, 0x81E8, 0x904E, 0x7A31, 0x91CF, 0x9B3B, 0x5E02, 0x5047, 0x96E2, 0x5408, 0x56E0, 0x6539, 0x4F5C, 0x70BA, 0x53D6, 0x6C42, 0x5949, 0x81F4, 0x5F97, 0x76CA, 0x7AED, 0x5805, 0x5229, 0x5B8C, 0x5099, 0x9673, 0x6545, 0x7AAE, 0x96E3, 0x5937, 0x5E73, 0x5EB8, 0x5DF2, 0x5FC5, 0x4E00, 0x53C3, 0x4EC0, 0x4F2F, 0x6666, 0x6714, 0x6642, 0x4E16, 0x671F, 0x5B98, 0x540F, 0x7235, 0x6B0A, 0x8861, 0x679C, 0x5BE6, 0x8070, 0x660E, 0x529F, 0x540D, 0x5317, 0x4E2D, 0x4E0B, 0x9075, 0x5F82, 0x5FB5, 0x6B78, 0x965F, 0x964D, 0x6D41, 0x653E, 0x6E38, 0x6D6E, 0x96C6, 0x91C7, 0x53D4, 0x632F, 0x63F4, 0x64CD, 0x79C9, 0x8209, 0x65AF, 0x4F10, 0x7A3C, 0x7A61, 0x7372, 0x7D0D, 0x4EA4, 0x932F, 0x88AB, 0x4EFB, 0x8CA0, 0x65BD, 0x7528, 0x5236, 0x8CBD, 0x61F7, 0x6155, 0x61F2, 0x60BC, 0x6DD1, 0x5E78, 0x5077, 0x8584, 0x96AA, 0x963B, 0x60A0, 0x7687, 0x6C38, 0x5B54, 0x4E9F, 0x5EB6, 0x88D8, 0x8910, 0x88F3, 0x5EAD, 0x5B87, 0x755D, 0x6240, 0x9A42, 0x99DF, 0x7B56, 0x77E2, 0x8EAC, 0x8EAB, 0x9818, 0x6B66, 0x4EC7, 0x8026, 0x5FB5, 0x6536, 0x767C, 0x5C01, 0x68C4, 0x4FDF, 0x9077, 0x5F99, 0x907A, 0x5931, 0x5B58, 0x8655, 0x5750, 0x9047, 0x63A5, 0x627F, 0x6276, 0x523A, 0x6298, 0x622E, 0x554F, 0x5C0D, 0x8A31, 0x7701, 0x5BE9, 0x616E, 0x6028, 0x5FCD, 0x5FEB, 0x8208, 0x5EE2, 0x8B8A, 0x66F2, 0x76F4, 0x9577, 0x5C0F, 0x8CAA, 0x5EC9, 0x8F15, 0x91CD, 0x72C2, 0x6B86, 0x5371, 0x9762, 0x53E3, 0x9F52, 0x8033, 0x76EE, 0x6307, 0x98EF, 0x98DF, 0x670D, 0x98FE, 0x5E03, 0x9B25, 0x5F0F, 0x6AA2, 0x82F1, 0x9748, 0x8C6A, 0x7136, 0x4E14, 0x6216, 0x66FE, 0x66F4, 0x6F38, 0x4FF1, 0x4E26, 0x800C, 0x82E5, 0x723E, 0x5EFA, 0x7F6E, 0x7F77, 0x5B78, 0x990A, 0x4E7E, 0x8B01, 0x5F87, 0x77EF, 0x6548, 0x7559, 0x9063, 0x9022, 0x5019, 0x5EF6, 0x52DD, 0x6557, 0x5B88, 0x7834, 0x9A0E, 0x4F0F, 0x570D, 0x7A81, 0x79BD, 0x7E31, 0x8CFC, 0x6291, 0x6309, 0x62D4, 0x64E2, 0x633E, 0x5C07, 0x70DD, 0x4EA8, 0x9867, 0x5BDF, 0x88C1, 0x65B7, 0x594F, 0x6555, 0x59D4, 0x6350, 0x8A73, 0x8A50, 0x8207, 0x596A, 0x81F3, 0x6B62, 0x5BE4, 0x5BD0, 0x6068, 0x9A5A, 0x5180, 0x8CB4, 0x8CE4, 0x58EF, 0x5927, 0x591A, 0x7BE4, 0x5C08, 0x58F9, 0x7A0D, 0x7565, 0x8F12, 0x7336, 0x9670, 0x967D, 0x4F11, 0x548E, 0x6A5F, 0x8981, 0x7956, 0x8CD3, 0x90CE, 0x7537, 0x90E8, 0x66F9, 0x9130, 0x91CC, 0x7344, 0x95D5, 0x7960, 0x7B2C, 0x5C4F, 0x5E33, 0x58C1, 0x6848, 0x5B57, 0x66F8, 0x9805, 0x4E73, 0x9AD4, 0x610F, 0x8AC2, 0x8ADB, 0x8AA3, 0x8FAF, 0x8A34, 0x6190, 0x9594, 0x540A, 0x9664, 0x62DC, 0x71DF, 0x52D9, 0x7A4D, 0x805A, 0x5C0B, 0x8FED, 0x4EE3, 0x66FF, 0x6210, 0x9042, 0x7CFB, 0x7D2F, 0x7F88, 0x4FC2, 0x727D, 0x7E23, 0x7D50, 0x7D55, 0x64C5, 0x62AB, 0x62C9, 0x59E6, 0x56DE, 0x96C5, 0x4FD7, 0x516C, 0x79C1, 0x504F, 0x5168, 0x7368, 0x7279, 0x919C, 0x964B, 0x7A62, 0x7384, 0x7D20, 0x767D, 0x65B9, 0x5919, 0x60DF, 0x9704, 0x6F22, 0x666F, 0x66DC, 0x90FD, 0x9091, 0x9119, 0x908A, 0x585E, 0x6BB7, 0x5468, 0x80E1, 0x865C, 0x620E, 0x5021, 0x512A, 0x4F0E, 0x7681, 0x5BA6, 0x8C4E, 0x81E7, 0x7372, 0x797F, 0x4F4D, 0x7522, 0x696D, 0x8CA8, 0x8CC2, 0x8CC7, 0x8CA1, 0x8CC4, 0x6027, 0x60C5, 0x8072, 0x97FF, 0x62F3, 0x8173, 0x7AEF, 0x7DD2, 0x7BC0, 0x5EA6, 0x8B70, 0x8AD6, 0x8AF7, 0x8CB6, 0x8B2B, 0x65A5, 0x5BA3, 0x8912, 0x8D08, 0x985B, 0x8986, 0x7387, 0x8A63, 0x6B77, 0x5BD3, 0x5BC4, 0x7981, 0x6212, 0x6043, 0x73A9, 0x8086, 0x6577, 0x5316, 0x52A0, 0x640D, 0x523B, 0x52D2, 0x9B31, 0x8212, 0x5F35, 0x5F1B, 0x662F, 0x975E, 0x80FD, 0x53EF, 0x4EE5, 0x51E1, 0x8056, 0x6B98, 0x66B4, 0x7518, 0x8F9B, 0x9BAE, 0x655D, 0x5BD2, 0x6EAB, 0x5E7D, 0x51A5, 0x5967, 0x7CBE, 0x773E, 0x4FBF, 0x5609, 0x907D, 0x901F, 0x5F4C, 0x6108, 0x5C24, 0x6975, 0x751A, 0x6700, 0x592B, 0x5A66, 0x5B30, 0x5B69, 0x89AA, 0x7737, 0x7AF9, 0x6728, 0x7A40, 0x58D1, 0x4EAD, 0x81FA, 0x90CA, 0x589F, 0x6750, 0x624D, 0x7C3F, 0x7C4D, 0x72C0, 0x985E, 0x58FD, 0x547D, 0x5FD7, 0x8DA3, 0x6D95, 0x6CE3, 0x818F, 0x6FA4, 0x5E37, 0x84CB, 0x6897, 0x6982, 0x672C, 0x672B, 0x7D00, 0x8F09, 0x76E3, 0x64AB, 0x6E38, 0x63DA, 0x6297, 0x596E, 0x6C88, 0x6C92, 0x901A, 0x9054, 0x8FA8, 0x6790, 0x5224, 0x5207, 0x63A8, 0x79FB, 0x9769, 0x805E, 0x5BBF, 0x96A8, 0x6CAE, 0x64EC, 0x6E2C, 0x7576, 0x9808, 0x9952, 0x79C0, 0x9E97, 0x5DE5, 0x535A, 0x6838, 0x5947, 0x5076, 0x4E39, 0x7D05, 0x5141, 0x821B, 0x5BE7, 0x8C6B, 0x5C1A, 0x6538, 0x752B, 0x804A, 0x532A, 0x53A5, 0x7D93, 0x5178, 0x7C21, 0x7BC7, 0x8A5E, 0x8CE6, 0x5E8F, 0x9298, 0x8A84, 0x8D0A, 0x7AE0, 0x8868, 0x65E8, 0x98A8, 0x9A37, 0x7FF0, 0x85FB, 0x97FB, 0x5F8B, 0x69AE, 0x83EF, 0x8ECC, 0x7BC4, 0x898F, 0x5247, 0x6E96, 0x6606, 0x5F1F, 0x5F62, 0x8DE1, 0x7DBA, 0x7DF4, 0x502B, 0x5E38, 0x7DB2, 0x7DAD, 0x5951, 0x5E7E, 0x59CB, 0x7D42, 0x7F9E, 0x8FB1, 0x5275, 0x9020, 0x6F5B, 0x85CF, 0x6B65, 0x5C65, 0x6795, 0x85C9, 0x51CC, 0x53B2, 0x8105, 0x8FEB, 0x9695, 0x843D, 0x904B, 0x8F38, 0x5FAD, 0x5F79, 0x620D, 0x52DF, 0x5439, 0x5531, 0x53E9, 0x5F48, 0x8B80, 0x557C, 0x865F, 0x8A0A, 0x8A70, 0x6558, 0x8A34, 0x6479, 0x5BEB, 0x6392, 0x6518, 0x7AC4, 0x5217, 0x5782, 0x5C0A, 0x76DB, 0x865B, 0x6789, 0x548C, 0x9806, 0x51DC, 0x51DD, 0x721B, 0x6F2B, 0x8D64, 0x78A7, 0x9752, 0x84BC, 0x4E4D, 0x66AB, 0x6BCF, 0x65E2, 0x537F, 0x5085, 0x5100, 0x5BB9, 0x7965, 0x6B83, 0x689D, 0x7406, 0x652F, 0x8449, 0x6735, 0x7A4E, 0x8ED2, 0x5195, 0x5EBE, 0x5EE9, 0x5E1B, 0x7E37, 0x6243, 0x7256, 0x6979, 0x6ABB, 0x6881, 0x9675, 0x6D25, 0x6D66, 0x7587, 0x964C, 0x6661, 0x66DB, 0x584A, 0x792B, 0x6387, 0x63A7, 0x636B, 0x628A, 0x6311, 0x6414, 0x6295, 0x64F2, 0x905E, 0x8E48, 0x8EA1, 0x5347, 0x7DE3, 0x5043, 0x50D5, 0x6583, 0x50BE, 0x8046, 0x773A, 0x7747, 0x7704, 0x77BB, 0x56DE, 0x9084, 0x901D, 0x5206, 0x8A23, 0x60B8, 0x615F, 0x60B5, 0x6168, 0x8B66, 0x60D5, 0x6B32, 0x611F, 0x914C, 0x9179, 0x9163, 0x89BA, 0x592E, 0x95CC, 0x6E05, 0x6F84, 0x6E3E, 0x5B89, 0x9591, 0x4E56, 0x4E92, 0x7E41, 0x7169, 0x6025, 0x5FFD, 0x4F46, 0x661F, 0x8FB0, 0x5CB3, 0x4E18, 0x5DBA, 0x68E7, 0x95A3, 0x7538, 0x85E9, 0x82D1, 0x96B4, 0x5879, 0x58B3, 0x8E4A, 0x5F91, 0x6C40, 0x6D32, 0x6E1A, 0x768B, 0x6DAF, 0x5858, 0x57A0, 0x8F26, 0x8F42, 0x8F45, 0x8F4D, 0x7C2A, 0x7E93, 0x7D31, 0x7DAC, 0x887E, 0x8966, 0x8882, 0x7FB9, 0x98E7, 0x7D72, 0x7BA1, 0x5F26, 0x9F13, 0x9F19, 0x50DA, 0x7FA4, 0x8F29, 0x601D, 0x7D22, 0x9452, 0x8CDE, 0x6599, 0x60F3, 0x5360, 0x535C, 0x6232, 0x5F04, 0x52D5, 0x5B9A, 0x99D0, 0x4F4F, 0x4F9D, 0x501A, 0x96D5, 0x88FD, 0x751F, 0x6D88, 0x6DF9, 0x6F0F, 0x6CDB, 0x6DB5, 0x8499, 0x853D, 0x852D, 0x7099, 0x5556, 0x9909, 0x6582, 0x8CA2, 0x6FC0, 0x6FEF, 0x62C2, 0x9006, 0x51CB, 0x96F6, 0x5C60, 0x6EC5, 0x7F44, 0x76E1, 0x4E86, 0x8096, 0x66A8, 0x902E, 0x669D, 0x9EEF, 0x7E96, 0x6089, 0x8D0F, 0x77ED, 0x9A55, 0x6162, 0x5984, 0x5C64, 0x55AC, 0x803F, 0x6E3A, 0x7E1F, 0x7A20, 0x7D9C, 0x96DC, 0x5FA7, 0x5875, 0x9744, 0x5DD2, 0x5CA9, 0x963F, 0x9685, 0x7554, 0x969B, 0x7DB8, 0x7E82, 0x5E8A, 0x84D0, 0x599D, 0x5333, 0x5EDA, 0x7B75, 0x808C, 0x819A)

$char = $doc.selectedSubstrings
$char = $char.join ''
$charValue = $char.characterAtIndex 0

$i = $list.indexOfValue $charValue
if $i == -1
   $char.findAndReplace '(?<=\A.)\p{Any}+', '', 'E'
   $output = "'$char' not in the list"
else
   $output = $i + 1
end

$j -= 1  # for testing
end  # for testing
exit  # for testing

exit $output

P.S. I’d like to have selectedSubstring command.


2010-09-16 06:56:52
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Kino wrote:
Perhaps did you exclude from the loop Read Selection which seems to be slow? And/or oh! are you running an ultra-fast i5/i7 Mac?!?

Ah perhaps I did accidentally exclude Read Selection from the 1000x loop. I see it runs a few seconds slower with that command in the loop. I was testing on a Mac mini myself :)

Quote:
Anyway the macro below takes 2 seconds on my Mac mini 2 GHz when running it 1000 times with ‘膚’ (the last item in the array) selected.

Very nice. Your last macro also runs faster for me, in the 1.0-1.5 second range.

Quote:
P.S. I’d like to have selectedSubstring command.

Consider it done (for a future NWP upgrade).


2010-09-16 09:19:30
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 15 posts ] 

Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software