Quick Search for:  in language:    
CPU,31415,code,benchmarks,calculating,with,br
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
C/ C++ Stats

 Code: 715,766. lines
 Jobs: 107. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for C/ C++.
Click here to see a screenshot of this code!c++ basic all
By Hamdi Farah on 1/28

(Screen Shot)

biopro.c --- search for words that do not exist in the dictionary file
By Donald Bono on 1/28


BruteForce Engine
By koby-GR on 1/28


Catch Me If U Can !!
By ashish & manas on 1/27


nOS ver 1.0
By - Snake - on 1/27


WordInFile.c -- look up a dictionary file for the word you just entered (source code only)
By Donald Bono on 1/27


WordInList.EXE -- search a dictionary file (included)
By Donald Bono on 1/27


Alymars Dice Roller
By roy sawyer III on 1/26


LCI_EXPORTER
By Leandro Pelorosso on 1/26


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Pi calculator / bench mark

Print
Email
 
VB icon
Submitted on: 12/15/2003 6:50:11 PM
By: Vadim Oguievetski 
Level: Beginner
User Rating: Unrated
Compatibility:C++ (general), Microsoft Visual C++

Users have accessed this code 593 times.
 

(About the author)
 
     My code benchmarks the CPU buy calculating Pi (3.1415....) with brute force

 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

//**************************************
//     
//INCLUDE files for :Pi calculator / ben
//     ch mark
//**************************************
//     
#include <iostream.h>
#include <windows.h>
#include <time.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

//**************************************
//     
// Name: Pi calculator / bench mark
// Description:My code benchmarks the CP
//     U buy calculating Pi (3.1415....) with b
//     rute force
// By: Vadim Oguievetski
//
// Inputs:#no inputs#
//
// Returns:returns the value of Pi and t
//     he time taken
//
// Assumes:try to tweek the 'r' value
//
// Side Effects:My program might make yo
//     u want to have a pie which can cause obe
//     sity.
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=7294&lngWId;=3//for details.//**************************************
//     

#include <iostream.h>
#include <windows.h>
#include <time.h>
#define r 20000
#define r2 r*r
void main()
    {
    	double a, b, x, y;
    	double count = 0;
    	int per, check = 0;
    	int start = 0;
    	int end = 0;
    	cout << endl;
    	cout << "** Welcome to Pi-Bench 1.01: *************************************" << endl;
    	cout << "** Intro: ********************************************************" << endl;
    	cout << endl;
    	cout << "This app was coded by Vadim Oguievetski. " << endl;
    	cout << "Special tanks to Pi for allowing me to calculate itself" << endl;
    	cout << "Please note that this bench mark is built for the 32 bit single" << endl;
    	cout << "threading processor. so if your CPU is ether hyper threading or" << endl;
    	cout << "64 bit then give yourself some well deserved credit!\n" << endl;
    	cout << "Please be informed that Pi is a registered trademark of the Pi" << endl;
    	cout << "cooperation and should not be used with out a licence" << endl;
    	cout << endl;
    	cout << "** Here is the math side of tihs app: ****************************" << endl;
    	cout << endl;
    	cout << "This app simulates the process of tearing a paper circle into" << endl;
    	cout << "equal sized squares and the counting all squares bigger than half," << endl;
    	cout << "then divide the number by the square of the radius to get *Pi*." << endl;
    	cout << endl;
    	cout << "******************************************************************" << endl;
    	cout << endl;
    	system("PAUSE");
    cout << endl << ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,,.. .,,TM,";
    cout << endl << ",,,,,,,,,,,,,. ,,,,";
    cout << endl << ",,,,,,,,,,.. :7@MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM: ,,,";
    cout << endl << ",,,,,,,,.. :;aBMMWZi r0MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMZX .,,";
    cout << endl << ",,,,,,,. :r:.aZM@MMMM@MMMMMMMMMMMMMMMMMMMMM@@@MMMMMMMMMMMMMMMMMMMMWr .,,";
    cout << endl << ",,,,,,. :iMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMBi .,,";
    cout << endl << ",,,,,. i MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMW; .,,";
    cout << endl << ",,,,. SWMMMMMMMMMMMMMWMMMMM0MMMMMMMMMMMMMMMMBMMMMMMM@MMMMMMMMMMMMMMMM2 .,,";
    cout << endl << ",,,. MMMMMM@W88arXii iMMMMMr0riiiiiiiiiiiii XMMMMMM@ZXriiiiiiiiiii;i,: .,,";
    cout << endl << ",,, MMMMM8W8r.:MMMMMXXMMMMMMMr2 .,,,";
    cout << endl << ",, MMMM8W2r..... MMMMMMZ7 ............ MMMMMMMaZ ...........,,,,,,,,";
    cout << endl << ",. MMM0WZ. .,,,,,,. MMMMM0B2 ,,,,,,,,,,,, M@@MMMM0S ,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",. MMM88:.,,,,,,, MMMMM8Z. ,,,,,,,,,,,, MWMMMMBZ. .,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",. ,7ar .,,,,,,,,, MMMMMB8, ,,,,,,,,,,,, SMMMMMMBBi .,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,. .,,,,,,,,,, MMMMMZ8: ,,,,,,,,,,,. ZMMMMMMM7: ,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,....,,,,,,,,,,,, MMMMM0Xi ,,,,,,,,,,, WMBMMMMB2 ,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,,,, rMWMMMMS ,,,,,,,,,,, MM@MMMMBi ,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,,,, MMMMMW0X ,,,,,,,,,,, MMMMMMMBr .,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,,, MMMMMM0i .,,,,,,,,,,, MMMMMMMX7 .,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,,, MWMMM@0r .,,,,,,,,,,, MWMMMMMai .,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,,. SMBMMMMS7 .,,,,,,,,,,, 2MiMMMMM0: ,,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,, MMMMMMMZ, ,,,,,,,,,,,, MMWMMMMXW. ,,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,, MaMMMM22 ,,,,,,,,,,,, MMMMMMMSZ ,,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,,, 8MaMMMM22 ,,,,,,,,,,,, MMMMMMM28 ,,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,, M82MMMMa2 ,,,,,,,,,,,, MMMMMMM28 ,,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,,. aM2MMMMB0X .,,,,,,,,,,,, MMMMMMMSZ ,,,,,,,,,,,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,,. .M2.MMMMZa. ,,,,,,,,,,,,, MMMMMMMB2 ,,,,,,,,,,,..,,,,";
    cout << endl << ",,,,,,,,,,,,,,, ZX ZMMMMZZ: ,,,,,,,,,,,,, MMMMMMMMa ,,,,,,,,,,, ri .,,,";
    cout << endl << ",,,,,,,,,,,,,, a0i MMMMMWS. ,,,,,,,,,,,,, MMMMMMMM8i .,,,,,,,,, MMM, ,,,";
    cout << endl << ",,,,,,,,,,,,. 2aa @MMMMWZi ,,,,,,,,,,,,, MMMMMMMMM, .,,,,,,,MMMa2.,,,";
    cout << endl << ",,,,,,,,,,,. iX:r MMMMMM0; .,,,,,,,,,,,,, ZMMMMMMMMB,,,,.MMMaZi ,,,";
    cout << endl << ",,,,,,,,,,. ii ; MMMMMMa2 ,,,,,,,,,,,,,, ,MMMMMMMMMM8.MMMMZa ,,,";
    cout << endl << ",,,,,,,,, :. 7 WMMMMMMBS ,,,,,,,,,,,,,, MMMMMMMMMMMMMMMMMMMMMMM08; .,,,";
    cout << endl << ",,,,,,,,, .7:7 MMMMMMM88. .,,,,,,,,,,,,,,. ZMMMMMMMMMMMMMMMMMMMMMMWX. ,,,,";
    cout << endl << ",,,,,,,,. MMM@XMMMMMMM@0Z ,,,,,,,,,,,,,,,, MMMMMMMMMMMMMMMMMMMMM0B: .,,,,";
    cout << endl << ",,,,,,,,. MMMMMMMMMMMMWZ, .,,,,,,,,,,,,,,,,. :MMMMMMMMMMMMMMMMMMM8W; ,,,,,";
    cout << endl << ",,,,,,,,. MMMMMMMMMMMB8r ,,,,,,,,,,,,,,,,,, :MMMMMMMMMMMMMMMMMWWa .,,,,,";
    cout << endl << ",,,,,,,,. aMMMMMMMMMWW; ,,,,,,,,,,,,,,,,,,,,MMMMMMMMMMMMMMWBa.,,,,,,";
    cout << endl << ",,,,,,,,,MMMMMMM@Wi .,,,,,,,,,,,,,,,,,,,,,0MMMMMMMMM@W0i,,,,,,,,";
    cout << endl << ",,,,,,,,,,,rSSS.,,,,,,,,,,,,,,,,,,,,,,,. ,;78SXS .,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,. .,,,,,,,,,,,,,,,,,,,,,,,,,,,,..,,,,,,,,,,,";
    cout << endl << ",,,,,,,,,,,,,,.....,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,......,,,,,,,,,,,,,,,";
    	cout << endl << endl;
    	system("PAUSE");
    	start = GetTickCount();
    	a = -r;
    	b = -r;
    	while(a<=r)
        	{
        	x = a;
        	b = -r;
        		while(b<=r)
            		{
            			y=b;
            				if(x*x+y*y<=r*r)
            					count++;
            			b++;
            		}
            		per=int(((a+r)/(2*r))*100);
            		if(per>check)
                		{
                			cout << "Percent completed = " << per << "%" << endl;
                			check = per;
                		}
                	a++;
                	}
                	end = GetTickCount();
                	cout << "\nCalculated value of Pi is " << count/(r*r) << endl;
                	cout << "\nAnd it only took your CPU: " << end - start << "ms" << endl;
                	system("PAUSE");
            }

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | C/ C++ Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.