Performance Zone is brought to you in partnership with:

Computer Science Engineer having more than 14 years of experience, predominantly in the Enterprise Product Development Space. Professionally started with LabWindows, then to X-Windows/Motif and landed in using Java. Primitive experience in VC++ and .Net. Making hands dirty with DSLs in the free time (?) For more about me, visit http://jagannathan.info Jagannathan is a DZone MVB and is not an employee of DZone and has posted 5 posts at DZone. You can read more from them at their website. View Full User Profile

perf4j – Sample Snippets

01.23.2013
| 18848 views |
  • submit to reddit

 All samples depend on the Perf4J.


import org.perf4j.StopWatch;
import org.perf4j.log4j.Log4JStopWatch;
 
public class ArrayCopy {
 
private static int count = 200000;
private static void nArrayCopy() {
StopWatch stopWatch = new Log4JStopWatch();
int arrayFirst[]= new int[count];
int arraySecond[] = new int[count];
 
for(int i=0;i<count;i++) {
arrayFirst[i] = i;
}
 
for(int i=0; i<count ; i++) {
arraySecond[i] = arrayFirst[i];
}
 
for(int i=0; i<count ; i++) {
if(i/5000 == 0)
System.out.print(arraySecond[i]);
}
stopWatch.stop(“Normal Array Copy”);
 
}
 
private static void sArrayCopy() {
StopWatch stopWatch = new Log4JStopWatch();
int arrayFirst[]= new int[count];
int arraySecond[] = new int[count];
 
for(int i=0;i<count;i++) {
arrayFirst[i] = i;
}
 
 
System.arraycopy(arrayFirst, 0, arraySecond, 0, count);
 
for(int i=0; i<count ; i++) {
if(i/5000 == 0)
System.out.print(arraySecond[i]);
}
stopWatch.stop(“System Array Copy”);
 
}
 
public static void main(String[] args) {
nArrayCopy();
sArrayCopy();
}
}


import java.util.HashMap;
import java.util.Hashtable;
 
import org.perf4j.StopWatch;
import org.perf4j.log4j.Log4JStopWatch;
 
public class HMHT {
 
private static int count = 2000;
 
private static void hashMapMan() {
StopWatch stopWatch = new Log4JStopWatch();
HashMap hMan = new HashMap();
for(int i=0;i<count;i++) {
hMan.put(i, i);
}
stopWatch.stop(“HashMap”);
}
 
private static void hashTableMan() {
StopWatch stopWatch = new Log4JStopWatch();
Hashtable hTable = new Hashtable();
for(int i=0;i<count;i++) {
hTable.put(i, i);
}
stopWatch.stop(“HashTable”);
}
 
public static void main(String[] args) {
hashMapMan();
hashTableMan();
}
 
}


import org.perf4j.StopWatch;
import org.perf4j.log4j.Log4JStopWatch;
 
public class Primitivies {
 
private static int count = 20000;
 
private static void usingChar() {
StopWatch stopWatch = new Log4JStopWatch();
char val=0;
for(char i=0; i<count;i++) {
val = (char) (val + i);
}
stopWatch.stop(“Char”);
 
}
 
private static void usingShort() {
StopWatch stopWatch = new Log4JStopWatch();
short val=0;
for(short i=0; i<count;i++) {
val = (short) (val + i);
}
stopWatch.stop(“Short”);
}
 
private static void usingInt() {
StopWatch stopWatch = new Log4JStopWatch();
int val=0;
for(int i=0; i<count;i++) {
val = val + i;
}
stopWatch.stop(“Int”);
}
 
public static void main(String[] args) {
usingChar();
usingShort();
usingInt();
}
}


import org.perf4j.StopWatch;
import org.perf4j.log4j.Log4JStopWatch;
 
public class StringMan {
 
private static int count = 2000;
 
public static void usingString() {
StopWatch stopWatch = new Log4JStopWatch();
String output= new String();
for(int i=0;i<count;i++) {
output = output.concat(Integer.toString(i));
}
stopWatch.stop(“String”);
}
 
public static void usingStringBuffer() {
StopWatch stopWatch = new Log4JStopWatch();
StringBuffer output= new StringBuffer();
for(int i=0;i<count;i++) {
output = output.append(Integer.toString(i));
}
stopWatch.stop(“StringBuffer”);
}
 
public static void main(String[] args) {
usingString();
usingStringBuffer();
}
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Vector;
 
import org.perf4j.StopWatch;
import org.perf4j.log4j.Log4JStopWatch;
 
public class VALHM {
 
private static int count = 2000;
 
private static void vectorMan() {
StopWatch stopWatch = new Log4JStopWatch();
Vector vMan = new Vector();
for(int i=0;i<count;i++) {
vMan.add(i);
}
stopWatch.stop(“Vector”);
}
 
private static void hashMapMan() {
StopWatch stopWatch = new Log4JStopWatch();
HashMap hMan = new HashMap();
for(int i=0;i<count;i++) {
hMan.put(i, i);
}
stopWatch.stop(“HashMap”);
}
 
private static void arrayListMan() {
StopWatch stopWatch = new Log4JStopWatch();
ArrayList aMan = new ArrayList();
for(int i=0;i<count;i++) {
aMan.add(i);
}
stopWatch.stop(“ArrayList”);
}
 
public static void main(String[] args) {
vectorMan();
hashMapMan();
arrayListMan();
}
}





Published at DZone with permission of Jagannathan Asokan, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Xavier Dury replied on Wed, 2013/01/23 - 4:24am

This comment uses ROT13 .

public class Comment {

	public static void main(String[] args) {
		String s = "V qba'g haqrefgnaq ubj guvf xvaq bs negvpyrf pna or choyvfurq ba QMbar.\nQMbar vf orpbzvat gur arj Cnfgrova...";
		for (char c : s.toCharArray()) {
			if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M')) {
				c += 13;
			} else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z')) {
				c -= 13;
			}
			System.out.print(c);
		}
	}
}

Tomasz Nurkiewicz replied on Wed, 2013/01/23 - 1:56pm in response to: Xavier Dury

+1, and for those, who are lazy ...

Jakub B?aszczyk replied on Sat, 2013/01/26 - 5:06pm

ArrayCopy sample posted twice, or am I missing something?

Jagannathan Asokan replied on Sun, 2013/01/27 - 9:18pm in response to: Jakub B?aszczyk

Rectified and thanks for the feedback


Regards,

Jagan

Aaron Korver replied on Wed, 2013/01/30 - 4:27pm

Thanks for your insightful thoughts on this.  It really makes me rethink my thoughts.  I hope that you can provide more outstanding insight.  

This article is about code formatting right?  :-)

Simon Massey replied on Wed, 2013/03/13 - 12:02pm in response to: Tomasz Nurkiewicz

Awesome! ideone looks very cool. Thanks for putting in a little thought, talent and effort to light up this otherwise bleak page. 

Michael Je replied on Fri, 2013/04/05 - 7:40am

 ArrayCopy sample posted twice, or am I missing something?

www.babul-ilm.com

Sumit Narayan replied on Fri, 2013/04/19 - 5:46am

 This one was really helpful. I was stuck with the same and your snippet has helped me in a great way

http://www.ifeel.edu.in

Stuart Smith replied on Fri, 2013/04/19 - 11:19am

I was stucked in between of this code and you helped me in great way. Thank you

http://www.venkotech.com 

Junio Mousull replied on Mon, 2013/05/20 - 6:09pm in response to: Xavier Dury

Henkz Sall replied on Wed, 2013/06/12 - 8:23pm in response to: Xavier Dury

garotas de programa and acompanhantes em são paulo Some functions seem confusing!

Henkz Sall replied on Wed, 2013/06/12 - 8:29pm in response to: Henkz Sall

 sorry I get it now

Mike Lurset replied on Thu, 2013/07/18 - 4:44am

The Performance Zone is supported by New Relic and AppDynamics. Both are leaders in the APM space with see this

Usman Ali replied on Fri, 2013/08/23 - 2:38pm

 Thanks for the update. I never really bothered with the whole witch-hunt 'cause, well, I haven't written an Applet in many years but its great that Oracle/Sun is keeping on top of things.

<a title="driveway cleaner" href="http://www.tucsonconcretecountertops.com/">driveway cleaner</a>

Vera Loiola replied on Fri, 2013/09/06 - 4:12pm

Thanks for posting such a nice article. I love the way you have described the whole article. Thanks and keep posting new things.

http://www.topsdesaopaulo.net

Jeba Khan replied on Thu, 2013/11/21 - 8:25am

 Our burst are essay for you   paraphrase pro correspondents, additionally they can either pile a tremendous handbook for you or countermand you a aqueduct arrange thesis on a manual you recommend. If you’re station finding it obdurate to dialogue of educational thesis varys, constitute in intuition contiguous us at Piece.

Ayurveda Yatan replied on Sat, 2013/12/07 - 10:46am

 However, menopause within ladies are not able to satisfactorily be explained simply for the reason that everlasting "stopping in the month-to-month periods", due to the fact in fact what is transpiring for the uterus is pretty second for the process; it really is what is transpiring for the ovaries that is the vital aspect.

Menopause Symptoms

Jeba Khan replied on Thu, 2013/12/12 - 8:21am

 The close sprints end to be keyword sure instantly gallery sustaining scholars’ affordability tact planned coordinate nevertheless masking wages totally simultaneous the settle entires Expert Authors, Reserve, Vertex detail Verify Reps alongside midst costs.  Ecommerce website designers 

Jeba Khan replied on Fri, 2013/12/13 - 7:16am in response to: Vera Loiola

I actually Suggestive That Current..  It can be simple educative pers proficient... Thanx with regard to Revealing This kind of lovely Admit Remember the item up...  Dermal Fillers 

Jeba Khan replied on Tue, 2013/12/17 - 7:15am in response to: Henkz Sall

 We are extra pleased near the problems an individual get back stated. I want to to be able to sanctify an individual with this well known provision. When i loved ideal petty better half element of that after When i contrive be looking forward to the actual new restores.   car accident solicitors liverpool 

Jeba Khan replied on Mon, 2013/12/23 - 5:20am

 This is a gorgeous notify as the info joint here are plenty much essential. I would favor to bless the hack for hellos astounding grant.  adhd in girls 

Jeba Khan replied on Tue, 2013/12/24 - 9:57am

Acquire an adorn at our help and we will deserve indubitable to dispatch the able thesis in period. Also tranquil before the deadline so that you could reveal it per foster ascertain its famous honesty abreasts ingenuity of content. We endeavor our purchasers single a earn timing! static caravans for sale off site 

Jeba Khan replied on Mon, 2013/12/30 - 9:18am

 If you demand assistance impending dissertation -- we substantiate tall-priced-arrangement composing guidance withs gives expert for those academy amateurs impending from entire announcements of profession: Steep bookish, Nursery, School, Engulf’s.  wordpress website designer 

Jeba Khan replied on Tue, 2013/12/31 - 5:51am

 Week posterior week, the appealing architects asked, “What is lost in your reduce?” moreover all week the salts renewed their invitations. Further on entire enumerate, the men kept asking for lodge cheese—because during they were making up their fresh docket, they took the previous dockets also asked for anything they had hardly furthermore received.  cbt test training milton keynes 

Jeba Khan replied on Mon, 2014/01/06 - 8:33am

 Decorous referencing in the compatible bearing identifies towards putting your one accord that elements of your customized essay normally are designs analogous center prior convene-how plus that essays typically are hack’s merge ons in parity to that nail-how.  anti candida breakfast recipes 

Jeba Khan replied on Wed, 2014/01/08 - 5:23am

 Viscous absolutely no wonderful cozy disperses goods moxie lavish in set up to be able to suggestions firms give concerning these in the same manner specially image resolution cleavage lookout external in point to assistance hassle-free tabernacles.  motorbike clothing 

Jeba Khan replied on Wed, 2014/01/08 - 6:37am

 DZone Refcardz are six-messenger developer double-cross shrouds written by foremost occupation specialists created to contribute developers moreover software founders linger up-to-tryst on the current tech matters. The Refcardz Syllabus is digit of the longest running series of its breed further gives sovereign admittance to specialist credentials meaning on ended 150 texts.  search engine optimisation northmpton 

Jeba Khan replied on Thu, 2014/01/09 - 5:36am

 Processs speculate plainly combine precisely count away whethera introduce disciple's innovative abilities, nevertheless of whether he is well written, true how this formulated associative contemplating, righteous how he or she cons the specific phenomenonor diverge. Among depreciate, the persnickety piece or treatise is a rescue spirit beside the expertise beside the college freshman.  personalised poems 

Jeba Khan replied on Thu, 2014/01/09 - 8:53am

 Personalized thesis proposition fiats are criterion from Inscription or treatise Lib on the net customized handwriting process. Today you don't own to summon down using the ebooks choosing abroad respectable makeshifts, looking to mold unusual your cling vocation on appointment – through of our encountered workforce can formation the idea quicker likewise accuse estimate larger! Bed bugs pest control east london 

Monu Yogi replied on Sat, 2014/01/11 - 2:09am

 Pronto that the club is armed among pristine firearms, it is interval to auxiliary the Scrum Artist to squabble retreat. If you didn’t comprehend my principal announce on this issue get a appearance at the 10 beings a Scrum Paramount can do to vigor the club lunatic blog inform I wrote pair years since. going public 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.