<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>&lt;blockquote&gt;Because indexOf tramples evaluate in term of execution time. While this is a small script, xpath definitely isn't the best option.&lt;/blockquote&gt;

I got evaluate to perform better than indexOf.

&lt;pre&gt;
javascript:words=&quot;Because it's your web.&quot;;

start=new Date().getTime();
regex = new RegExp(words);
if(regex.exec(document.body.innerHTML)) alert(&quot;regexp: &quot;+(new Date().getTime()-start));


start=new Date().getTime();
if (document.evaluate('//child::text()[contains(.,&quot;'+words+'&quot;)]', document, null, 9, null).singleNodeValue) alert(&quot;evaluate: &quot;+(new Date().getTime()-start));


start=new Date().getTime();
if (document.body.innerHTML.indexOf(words)&gt;-1) alert(&quot;indexOf: &quot;+(new Date().getTime()-start));
&lt;/pre&gt;</body>
  <body-html>&lt;p&gt;&lt;blockquote&gt;Because indexOf tramples evaluate in term of execution time. While this is a small script, xpath definitely isn't the best option.&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;I got evaluate to perform better than indexOf.&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;
javascript:words=&quot;Because it's your web.&quot;;

start=new Date().getTime();
regex = new RegExp(words);
if(regex.exec(document.body.innerHTML)) alert(&quot;regexp: &quot;+(new Date().getTime()-start));


start=new Date().getTime();
if (document.evaluate('//child::text()[contains(.,&quot;'+words+'&quot;)]', document, null, 9, null).singleNodeValue) alert(&quot;evaluate: &quot;+(new Date().getTime()-start));


start=new Date().getTime();
if (document.body.innerHTML.indexOf(words)&gt;-1) alert(&quot;indexOf: &quot;+(new Date().getTime()-start));
&lt;/pre&gt;&lt;/p&gt;</body-html>
  <created-at type="datetime">2008-12-20T12:47:58Z</created-at>
  <forumable-id type="integer">2</forumable-id>
  <forumable-type>Forum</forumable-type>
  <id type="integer">84969</id>
  <topic-id type="integer">18247</topic-id>
  <updated-at type="datetime">2008-12-20T12:47:58Z</updated-at>
  <user-agent nil="true"></user-agent>
  <user-id type="integer">21593</user-id>
</post>
