473,908 Members | 5,314 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 983

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

Similar topics

6
2375
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
1915
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 write this tool by myself (in PHP)?
6
2040
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 the website), this enables us to use the following PHP method:
7
4901
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
1923
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 resolution, this way put them into a very smaller area to work on. But If we do not fix the outtest...
0
9875
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11337
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10913
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11042
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10536
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4770
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
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3355
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.