473,569 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Big Deal


I just whipped up this code in c# using Regular Expressions.

I found 1037 instances of "Relf" in cola in 15 milliseconds:

#region Using directives

using System;
using System.Collecti ons.Generic;
using System.IO;
using System.Text;
using System.Text.Reg ularExpressions ;

#endregion

namespace ConsoleApplicat ion1
{
public class FileClass
{
public static void Main()
{
String s = ReadFromFile("c :\\sample\\Cola .txt");

Regex rex = new Regex("Relf");

DateTime init = DateTime.Now;

int icount = rex.Matches(s). Count; // returns 1

DateTime end = DateTime.Now;

TimeSpan duration = end.Subtract(in it);

Console.WriteLi ne("number of relfs " + icount);
Console.WriteLi ne(duration.Mil liseconds);


}
static String ReadFromFile(st ring filename)
{
StreamReader SR;
String S;
SR = File.OpenText(f ilename);
S = SR.ReadToEnd();
SR.Close();
return S;
}
}
}

Jeff_Relf wrote:
Jeff_Relf ( 30, 10.28 P, A Individual.NET, X ),
Hi Kelsey, Oops my last attempt only searched ten thousand words,
This time I'm searching 100 thousand words.

I'm using Cola.TXT as my test file, which is about 4 megs,
and contains over 2,000 of the most recent articles.

My web page is down right now... too much traffic ?

But when it comes up, I hope to put a more recent Cola.TXT here:
( I say, hope, because I'm using NoCharge.COM, free dialup )
http://www.Cotse.NET/users/jeffrelf/Cola.TXT

Only spaces and below ( Ascii ) were considered whitespace.

Here were my latest results:
Searching the first one hundred thousand words in Cola.TXT.

.00167 Seconds to find 12 occurences of Relf .
.00089 Seconds to find 0 occurences of sesquipedalian .

My machine is very slow too, the L2 cache is only 128 KB,
with 256 MB of DRAM and a 40 gig hard disk.

When my web page comes up I'll put the .EXE and .CPP files here:
http://www.Cotse.NET/users/jeffrelf/Search.EXE
http://www.Cotse.NET/users/jeffrelf/Search.CPP

Not including my standard macros, but including the timing code,
this was my main(): <<
main() {
QueryPerformanc eFrequency( ( Quad * ) & Secnd ); Secnd_Dub = Secnd ;
FILE * fp = fopen( "Cola.TXT", "r" );
if ( ! fp ) { printf("_ Word.TXT _ Can't be Read." ); return ; }
int Sz = filelength( fileno( fp ) ) + 1 ; LnT Ln = { 0 };
{ LnP B = ( LnP ) malloc( Sz ); Sz = fread( B, 1, Sz, fp );
fclose( fp ); fp = fopen( "Results.TX T", "w" );
B [ Sz ] = 0 ; LnP P = B ; int Ch = * P --, Ch2 ;
GoToDark
Loop( 100000 ) { Inc ( Ln ) = P ; if ( ! Ch ) break ; Next_Tok }
if ( J < LLL ) {
fprintf( fp, "Found %d thousand words, needed 100.", J / 1000 );
fclose( fp ); return ; } }
fprintf( fp
, "Searching the first one hundred thousand words in Cola.TXT.\n\n") ;
LnP Pats [] = { "Relf", "sesquipedalian " };
Loop( sizeof Pats / sizeof * Pats ) { LnP Pat = Pats [ J ];
double Mark = Secs ;
int Cnt = 0 ; LoopXx ( Ln ) if ( Eq( P, Pat ) ) Cnt ++ ;
double Dur = Secs - Mark ;
char SecStr [ 99 ] ; sprintf( SecStr, "%1.5f" , Dur );
fprintf( fp, "%s Seconds to find %d occurences of %s .\n"
, SecStr + ( * SecStr == '0' ), Cnt, Pat ); } fclose( fp ); } >>

Jul 21 '05 #1
0 974

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2358
by: Alex Shi | last post by:
Any good idea or a reference link to deal with search engine for php web pages? Thanks in advance! Alex
9
1895
by: _mario lat | last post by:
I'd like to deal (update, deal, insert....) a database (with tables and relationship between these) by a tool written in php. I need to share and work on a database with other people. I'd like to find an interface like microsoft access interface or that let manipulate the db in easy vay. Which tool can I use? Or wich libray can I use for...
6
2023
by: christian9997 | last post by:
Hi We have started off using a $_GET parameter to keep track of the user's browser: We detect what browser the visitor is using when he first arrives on our website then we do a redirect to the same page adding on "&browser=IE" or "&browser=DOM" at the end of the url (and we keep the browser parameter in the URL the whole time he is on...
7
4865
by: rbt | last post by:
The house almost always wins or are my assumptions wrong... import random amounts = results = count = 0 while count < 10:
7
1908
by: rockdale | last post by:
Hi, How do you guys deal with the different clinet resolution? For example, you have 800*600, 1024*768 and 1280*1024 on client side. We used to put everything into a table with fixed width (the lowest width of your clients' resolutions) then put everything inside the table with a percentage width. But for those clients with higher...
0
7721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7699
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3669
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.