Unexpected result in efficieny comparson of Hashtable and ArrarList
I learned that Hashtable is much more efficient than ArrayList. To convince my self, I did the following:(a) create a file of 100000 channels acii range of 65 to 122 3 random letters. Foll. is the code I used.
import java.util.Random;
import java. IO;
Class RandomStrToFile {}
Public Shared Sub main (String [] args) {}
Random rnd = new Random();
long I, imax = 100000;
cNL tank;
String sFileName = "myrandom_strings.txt";
String sBuffer ="";
try {}
FileWriter fw = new FileWriter (sFileName);
BufferedWriter BW = new BufferedWriter (fw);
for (i = 0; i < imax; i ++) {}
sBuffer = "" + (char) (65 + (int) ((rnd.nextDouble ()) * 57)) + (char) (65 + (int) ((rnd.nextDouble ()) * 57)) + (char) (65 + (int) ((rnd.nextDouble ()) * 57));
BW. Write (sbuffer);
bw.newLine ();
System.out.println (sbuffer);
}
BW. Close();
FW. Close();
} catch (IOException e) {}
}
}
b. timed to create a unique valielist of the file above, nuer ArrayList and Hashtable respectively. Here is my code:
import java. IO;
Import Java.util;
public class test2 {}
Public Shared Sub main (String [] args) {}
String Slithe.
int iVal;
long startTime, endTime;
< String > ArrayList al = new ArrayList < String > ();
Hashtable ht = new Hashtable (4999); Use a prime number
try {}
////////////////////////////////////
FileReader fr = new FileReader("C:\\Home\\MyJava\\eclipse_proj\\MyFirst\\bin\\myrandom_strings.txt");
BufferedReader br = new BufferedReader (en);
startTime = System.currentTimeMillis ();
iVal = 0;
While ((mean = br.readLine ())! = null) {}
System.out.println (William);
iVal iVal = + 1;
If (! ht.contains (William)) {}
HT.put(iVal,sLine);
System.out.println (William);
}
}
endTime = System.currentTimeMillis ();
System.out.println ("elapsed time in the Hashtable is:" + (endTime-startTime));
Br. Close();
Fr. Close();
/////////////////////////////////////////
en = new FileReader("C:\\Home\\MyJava\\eclipse_proj\\MyFirst\\bin\\myrandom_strings.txt");
BR = new BufferedReader (en);
startTime = System.currentTimeMillis ();
iVal = 0;
While ((mean = br.readLine ())! = null) {}
System.out.println (William);
iVal iVal = + 1;
If (! al.contains (William)) {}
Al. Add (William);
System.out.println (William);
}
}
endTime = System.currentTimeMillis ();
System.out.println ("elapsed time of ArrayList is:" + (endTime-startTime));
Br. Close();
Fr. Close();
} catch (IOException e) {}
}
}
To my surprise Hashtable approach has been much slower Quen ArrayList approach. Am I missing something here?
user10035918 wrote:
OK, here we go. I can't get rid of the file
Yes, you can. You're not a file need to compare the performance of the list relative to the map. Since you don't get rid of it, I don't look at your test.
Here is the result of my test. Card is more than 10 000 times faster than the list here.
list took 20,828 ms to find 500 items
map took 16 ms to find 5,000 items
Here's the code.
package scratch;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
public class MapVList {
static List list = new ArrayList ();
static Map map = new HashMap ();
public static void main (String[] args) throws Exception {
for (int ix = 0; ix < 1000000; ix++) {
Thing thing = new Thing("abc" + ix + "xyz");
list.add(thing);
map.put(thing.name, thing);
}
long start;
long end;
long elapsed;
int ix;
start = System.currentTimeMillis ();
for (ix = 0; ix < 500; ix++) {
String name = "abc" + ix * 1000 + "xyz";
findInList(name);
}
end = System.currentTimeMillis ();
elapsed = end - start;
System.out.printf ("list took %,d ms to find %,d items%n", elapsed, ix);
start = System.currentTimeMillis ();
for (ix = 0; ix < 5000; ix++) {
String name = "abc" + ix * 100 + "xyz";
findInMap(name);
}
end = System.currentTimeMillis ();
elapsed = end - start;
System.out.printf ("map took %,d ms to find %,d items%n", elapsed, ix);
}
static void findInList (final String name) {
for (Thing thing : list) {
if (thing.name.equals(name)) {
return;
}
}
throw new RuntimeException("list did not find " + name);
}
static void findInMap(final String name) {
if (map.get(name) == null) {
throw new RuntimeException("map did not find " + name);
}
}
static class Thing {
String name;
Thing(String name) {
this.name = name;
}
}
}
Tags: Java
Similar Questions
-
Original title: cannot run Microsoft Fix It to Program_Install_and_Uninstall
When I run Microsoft Fix It for Program_Install_and_Uninstall, I get "we're sorry, but we encountered an unexpected problem, one or several upload components and cannot run the troubleshooter now...» »
Hello
Why you try to run the fix it tool?
Post to fix any problem with Microsoft tool in Microsoft Fix it Center forums.
http://social.Microsoft.com/forums/en-us/category/msftsupporttools -
Original title: unexpected reboot
My PC (Windows XP SP3) restarts unexpectedly when you run Picasa Google Chrome and since I installed Acrobat Reader 10 it also occurs with this program.
Maybe the problem is related to this message in log file:
SSD HDD access service-service & can not start due to the following error: the system cannot find the path given.
Source: Service Control ManagerI would be very grateful if you can help me.
Hello
Step 1: Use disable automatic restart on system failure option and check if you can find any error message. Previous post the error message complete and accurate which could help us help you better.
Steps to select Disable automatic restart on system failure option:
1. reboot the computer
2 start typing the F8 key
3. you get it anticipated the startup option window
4. Select DisaDisable automatic restart in the event of system failureStep 2: Check if the problem persists in the clean boot state.
From your computer by using a minimal set of drivers and startup programs so that you can determine if a background program is interfering with your game or program. This type of boot is known as a "clean boot".
Reference:
How to configure Windows XP to start in a "clean boot" State
http://support.Microsoft.com/kb/310353When you are finished troubleshooting, follow these steps to reset the computer to start as usual:
1. click on start and then click Run.
2. type msconfig and click OK.
The System Configuration Utility dialog box appears.
3. click on the tab general, click Normal Startup - load all services and device drivers and then click OK.
4. When prompted, click on restart to restart the computer. -
Multiplying by output of small polynomial coefficients on vi trendline and get unexpected results
I'd appreciate it if someone could shine any light on this problem for me.
I'm performing a polynomial regression with the VI express Curve Fitting. The express VI itself works very well. I used the polynomials it generates for the graph of a function in Excel and it looks perfect.
When I convert the signal to an array and then multiply by other values things start to go south.
The results of multiplications are wrong when some 'x' values are used. The strange thing for me, is that it does not work for all values of x.
Not sure if this is useful, but the expected values for x 0 through x 5 (bottom right, below) are:
x 0:-1,14
x 1: 16.11
x 2:6-3-19
x 3:-3.39E - 4
x 4: 6.76E - 7
X 5:-2.08e - 7
and the values displayed when the routine is running:
x 0:-1,14
x 1: 16.11
x 2: 25.57
x 3:-925.06
x 4: 104.25
x 5:-2017.87
Any ideas? I think a data type must be changed since the expected values are very small and the problem is only present for certain values of x.
If this is the case I don't know how to change the data type. The table contains double the conversion of the shape of the signal.
Thanks for any help,
Dave
Hi TCPlomp,
I just realized that I had x and is reversed in my entries "power x" function.
Thanks for letting me know about polynomial screws. Add those who should be more pleasant than to try to clean it.
Kind regards
Dave
-
Problem with pantone and 'effect of mix' gives 'of unexpected results.
Hey!
This is the case:
Im working on one design racing car and I need a pantone mix to match a graphic film 3 m.
I have a graphic film that will apply to the front of the car. This film of 3 m spesific equality / match pantone 165 C.
The other half of the car is supposed to have a printed film applied. on this impression, I have a mix (complex, cannot be used in this case degraded form) from a dark place
CMYK color and ending in Pantone 165 C. The result of the printing is not as I want it to be. Smooth smoothing on the screen has turned into something and is not quite usable.My question is that is can not turn the spot pantone to process, because then I will not have control over the outcome of the printer. The people of said production if they print in CMYK the result will not be 165 C.
I need the Pantone to be printed in Pantone 165C to match the packaging film.I did some testprints and it seems to be an issue between illustrator and printer.
Is it possible to solve this problem and still have total control of color?
Greatfull for any help in this matter!
Too everyone. Thanks for all the good advice and to comment on it.
The solution for me was simply to send the file to the production elsewhere.They have the newest equipment/digital printer, there is.
Probably not very satisfactory for the geek inside you, but he saved for sure to spend more time on
This. Thanks again! -
unexpected results of the Group and the merger of processor
Hi team,
I use a processor of group and the merger in a process that includes "Store-num" and the "Cust-num" and mergers based on the most common value.
I have few records store-Num = 42 and a few records store-num = 426. But for the same "Cust-num" for these two stores, store-num ' 426' we replace "42"
My point is that these documents should not have grouped at all.
No idea why this happen?
Kind regards
Ravi
Yes, that's correct. Dates will be converted to a string representation of the date.
-
My Windows Vista PC completely stops unexpectedly and without warning. Sometimes several times a day and sometimes not at all. When I turn it back on, sometimes I have a blue screen that tells me that the PC has experienced an unexpected shutdown and communicate with my local technician. However when turning on, I am always able to return to my office. My anti-virus support told me that it is not related to a virus. Help!
It is likely some equipment or device driver issue (although we can not entrierly a problem of software). I need a lot more information on this blue screen - EXACTLY what it says Word for Word with all the codes. Read the messages and follow the procedures established by the MVP of the spirit in the following thread on the Blue Screen of Death. They should help you solve your problem. http://social.answers.Microsoft.com/forums/en-us/vistahardware/thread/8cd8362e-7d06-46FB-afd7-84d54b6a8ea7 I know it's long but a blue screen problems problem may take some time because there are so many different causes and we must find the right to try to identify the problem and then find a way to fix it. One of the elements in his post is a method to prevent the system to reboot when a blue screen if you have the time to copy the information. If the system is not turned off, but the screen does not stay up long, press prtscrn to copy the screen, then when the system boots to open Microsoft Paint, click on the Open box and click Ctrl + V to paste here you have plenty of time to copy the information and post it here so we can look at. Do not forget to include EVERYTHING - it is unclear what could be of crucial importance.
I repeat the procedures in the messages of the spirit in the link above - just follow them and answer back here with the results. Want to make interim reports before the end of the stteps is perfectly OK - in fact, I suggest you do that so I can help guide you and maybe eliminate some of the steps because they will provide no information, that we don't already know (or will not solve the problem because of the information that we already know.
A question, is your so hot PC anywhere on it that if you hold your hand on it, you will need to detach due to heat? Overheating is a common cause of this type of problem. Check that the fan doesn't work and all intake and exhaust ports are clean of dust, lint, or any other obstacle. If this is a desktop computer, remove the cover and clean the entire interior to remove dust and lint and anything else that doesn't belong. Make sure you do not loosen or detach the wiring or the accessories cards or RAM chips. Don't bother if it's a laptop - it's too difficult to get inside to do a proper clean-up - just make sure that the fan is running and that the vents are clear.
I hope this helps. I look forward to your reply with your comments about what you did to the spirit and procedures for detailed information on the blue screen error.
Good luck!
Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.
-
Unexpected results after calculation
Hello.
I have 3 databases of production which have worked successfully until Thursday.
FARM sales for the whole company per month.
EB2. Sale of a specific division a week.
EB3. Sale of a specific division and top ranges, per day.
Thursday.
The problem is that after calculation of EB3, the totals I see in the validation reports are incorrect when compared with the totals in the EB1.
The whole story is the display of incorrect results, not only the data for the current month, which is that I charge per day. I'm doing an incremental loading of the current and previous month only.
I took a backup and loaded in the EB3 and performed the calculation... once again the totals were incorrect.
Friday
When I compare the validation reports, totals in EB3 were as expected when checking against the EB1.
I did nothing for the outline, the backup is the same.
EB1 and EB2 were ok.
Saturday (today)
When I see the validation report today I noticed that EB3 has the same behavior; incorrect results.
And EB2 also contains unexpected values after calculation.
Have you encountered this problem before? Is there something specific I should review to determine and solve this problem?
Log files reflect not any message "error" or "fail".
Any comment is welcome.
Kind regards
JC
Difficult to clarify the question without knowing what actually do the calculations. Just a suggesiton wild as you see error every day replacing when you see good results just make a backup of contour and then use the problematic day contour compare to compare 2 contours. May be there are some jobs that you are not aware of the evolution of the sketch, thus destabilizing the whole of the data!
-
I'll go into search parameter in Google, Google results appear, click on one of the results on the Google page, the page back but then turns immediately to a Yahoo page. What follows is one of the pages Yahoo that the browser makes a redirect to: https://search.yahoo.com/yhs/errorhandler?hspart=gt & hsimp = yhse-gt & q = http % 3A % 2F % 2F www.doglitter.com%2FContent%2Fcss%2Fbullet_macIE & type = 576859
Hello
Looks like you may have some malware. Please check your add-ons for all suspicious extensions:
- Tools (or
) > Addons > Extensions
- Alternatively, you can type Subject: addons in your address bar and then click on "Extensions".
Delete all suspicious extensions that you find. Please follow the section Troubleshooting extensions, themes and problems of hardware acceleration to resolve common Firefox problems to find the cause. A useful way to find the culprit is disabling half of your modules, if it redirects is more then the culprit is in the half you off, otherwise it is the left half you activated.
When find you what is causing your problems, please let us know. This might help others with the same problem.
- Tools (or
-
VLOOKUP gives incorrect/unexpected results
HI guys
I used to think I had this spreadsheet thing down pat, but I find myself place after midnight with a VLOOKUP problem struggle! I really hope that you can show me the error of my ways...
I'm a convert from Excel so I can be taken in a mind control thing. I built a fairly large things relating of worksheet to do a lot of hobbies. I give it to the people who do the same kind of thing I do. It calculates the SOAP making tips, but I just found out that he gets things wrong - that is potentially dangerous.
I have a version simplified that what is happening in the picture above. In the F2 cell I: VLOOKUP (E2, values: results, 2, the search by proximity-match).
Now, I expect the numbers look down column B to find the value in cell E2 (1.90) and return the corresponding value of the C column (19.0). However, it does not. Instead, it provides the value of the cell above as if it could not find a match.
I tried every setting I can think of nothing doesn't. I put all the cells in the table above to a number to 2 decimal places. I even changed the exact match and close match but that just made things worse.
I know it's going to be something that will make me to get started me, but I need to fix no will not hurt. Any help gratefully received.
Cheers, Grant
PS I think I should mention that I do this on an iPad 2 air which is a bit new for me. And I just noticed I have write in figures for Mac. I'm sorry for that but I think that the versions are supposed to have the same capabilities?
I suspect that you use calculated values, rather than hand is entered in your "Search values" column, and even if you have formatted the column to display two decimal places, due to approximations that occur when doing calculations decimal on a computer using binary mathematics, the actual values using the VLOOKUP function differ slightly as many additional decimals on any line. If you wrap each calculation in a function to change the actual value with 2 decimal places, if the cell contains exactly what your put poster in the form, you will get the desired result.
-
all google search results link same "scraper" web site and random content
In my google for a topic search results, links to many of the results (not wikipedia, but most of the other sites 'reliable') lead to the same redirect URL: Search - milk .net, which then redirects to all kinds of content, random and other unwanted web pages. It's like having a pop up ad to support the browser. Should what settings I use to control these redirects in google? It doesn't looking for yahoo, BTW.
Hello
I don't know accurate information about research-milk, but this article should help you as she issues similar documents with "misappropriation of research."
https://support.Mozilla.org/en-us/KB/fix-problems-your-home-page-or-searchThank you
Michelle -
Whenever I do a search and click on a website search results, I am confused on some other Web site, usually a few ad-site.
I then have to click the back button and click the link again and it usually takes me on the site that I wanted to. Is it a problem with my computer of viruses, or a problem with firefox or google?Download, install and update as much of the following as possible until your infections are cleaned.
- The free versions of these scanners will detect infections and clean your system; no need to buy
- Scanners different malware detect some malware that other scanners do not have.
- If you are unable to download malicious programs,
- change the name of the Installer before you save the download on your hard drive, and
- Once installed, go to the installation to the program folder and change the name of the executable file of the program (i.e. for Malwarebytes Anti-Malware, change mbam.exe to xyz - mb.exe), then update the program and run the scan.
- You may need to download on a non infected computer, change the name of the Setup program, copy setup from a CD or USB and transport to your system for installation.
- Some stubborn malware should be deleted in Windows Safe Mode with setting network '. Warning: download all the tools first, then disconnect your modem before entering Mode Windows safe, as your firewall and AV/AS probably does not load mode Windows safe. See:
- Malwarebytes' Anti-Malware - http://www.malwarebytes.org/mbam.php
- SuperAntispyware - http://www.superantispyware.com/
- AdAware - http://www.lavasoftusa.com/software/adaware/
- Spybot Search & Destroy - http://www.safer-networking.org/en/index.html
- Windows Defender - http://www.microsoft.com/windows/products/winfamily/defender/default.mspx
- Dr Web Cureit - http://www.freedrweb.com/cureit/
If they cannot find or cannot remove the infection (s), post it in one of these specialized forums using malware removal:
- Read and follow their rules for display
- Follow the instructions to the letter
- Be patient; you are put in a queue and you will get a response when they get to your message
- http://bleepingcomputer.com
- http://www.spywareinfoforum.com/
- http://www.spywarewarrior.com/index.php
- http://Forum.aumha.org/
If this answer solved your problem, please click 'Solved It' next to this response when connected to the forum.
Not related to your question, but...
You may need to update some plug-ins. Check your plug-ins and update if necessary:
- Plugin check: https://www-trunk.stage.mozilla.com/en-US/plugincheck/
- Adobe Shockwave for Director Netscape plug-in: install (or update) the Shockwave with Firefox plugin
- Adobe PDF plugin for Firefox and Netscape: Installation/update Adobe Reader in Firefox
- Shockwave Flash (Adobe Flash or Flash): updated Flash in Firefox
- Next-generation Java plug-in for the Mozilla browser: install or update Java in Firefox
-
using the iPhone 6 s last updated - when trying to search using the result of Safari a padlock in front of him and nothing does not open in the list below!
Please wait until a fix is available at Apple.
Best.
-
DAQmxReadAnalogF64 gives unexpected results with 9239 of Ni - DAQmx
Hi all
I use a NI 9239 with a laser sensor, and I would like to acquire some pressure readings of the probe which measures the height. It works very well with Ni Max, but not in C + c++ / MFC app I am developing. I get something that looks like amplidied noise:
1 reading scale doesn't seem fair (pressure readings I get from range - 2E9 to 2E9)
2 changes in what the sensor is supposed to measure does not appear in my measurements at all, there is nothing other than the noise (as if I were acquires bad chain - this I double checked)
I would like to get the same result as in Ni Max, but may not know what wrong with my code (below).Thanks for your help,
Ben
DAQmx Configure Code
DAQmxErrChk (DAQmxCreateTask ("LaserReading", & taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"cDAQ1Mod1/ai0","",DAQmx_Val_Diff,-10,10,DAQmx_Val_Volts,));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,,10000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,5000));Starting code DAQmx
DAQmxErrChk (DAQmxStartTask (taskHandle));Reading DAQmx code
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,NUM,-1,DAQmx_Val_GroupByChannel,data,5000,&read,));TRACE sends the readings to the debug output
TRACE ('%d points\n acquis', read);
for (i = 0; i<5000;>5000;>
{
TRACE("%d\n",data[i]);
}DAQmxStopTask (taskHandle);
DAQmxClearTask (taskHandle);Found the answer to this problem, the problem was in the function TRACE which data acquired to the debugger output. %D %f for the float to TRACE("%f\n",data[i values changed]) - things are great now.
Thank you
Ben
-
Round off to infinity gives an unexpected result in my VI-
In the file attached, the resultant expected after round to-Infinity is 10, but what gives LabVIEW is 9. Anyone know why?
I divided by 0,166 10 1.66 and rounding to-infinity must give 10. But LabVIEW give 9.
In the digital representation of rounding error is the problem. The thing to remember is this decimal floating representations are approximations, while the real result of the calculation is 10, you can't really represent 10 exactly as a floating point number. While the indicator can say 10, internal representation of the answer is something like 9.999999999999999 - which is very, very close to 10, but when you go to turn it still gets rounded down.
This isn't a problem with LV, it is inherent in the floating point representations.
Mike...
Maybe you are looking for
-
Operating system preinstalled on all new Satellite C850 - 14 c is in Finnish
It is a strange problem. My brother has recently ordered a new laptop C850 - 14 c and it arrived by mail direct from the warehouse. When it out of the box, she had a UK Plug and a UK keyboard (we are in England), but when it was starting up it was al
-
Re: Stor.e Alu2 500 GB
Hello I bougth an external HARD drive and I am very unhappy because of the speed of transfer. I would like to know why speed reach 190 MB/s, up to 480 Mb/s transfer of large files and has a USB2 port. What I need to do to have a speed of 480 Mb/s as
-
SHAREit files: How to remove?
How can I delete files that I sent to iPod touch laptop computer Lenovo but is no longer needed on the iPod?
-
Cpmpaq Presario CQ % &: Presario keeps trying to load bad BONES
OK, so that's the second laptop that I got the same problem. My Presario CQ57 has Windows 7 as operating system. Recently, this thing started to have problems, instead of loading Windows 7, I can tell by his attempt to Vista loading screen instead. T
-
Someone knows how can I fix? I can't download anything because of this error, I tried a system restore, but that did not work. Any help would be great.