int elements = 2000000;
int tries = 100;
String values[] = new String[elements];
IntStream.range(0, elements).forEach( el -> { values[el]=el+""; } );
long t0 = System.currentTimeMillis();
IntStream.range(0, tries).parallel().forEach( i -> {
ArrayList al = new ArrayList();
IntStream.range(0, elements).parallel().forEach( j -> { al.add(values[j]); } );
});
long t1= System.currentTimeMillis();
IntStream.range(0, tries).parallel().forEach( i -> {
LinkedList ll = new LinkedList();
IntStream.range(0, elements).parallel().forEach( j -> { ll.add(values[j]); } );
});
long t2 = System.currentTimeMillis();
System.out.println("Add to ArrayList: "+(t1-t0)/tries+" ms avg, cnt="+elements+", tries="+tries);
System.out.println("Add to LinkedList: "+(t2-t1)/tries+" ms avg, cnt="+elements+", tries="+tries);
--
Add to ArrayList: 18 ms avg, cnt=2000000, tries=100
Add to LinkedList: 77 ms avg, cnt=2000000, tries=100
środa, lutego 22, 2017
Czy ArrayList jest szybsze od LinkedList? #3
piątek, lutego 17, 2017
Czy ArrayList jest szybsze od LinkedList? #2
ArrayListal = new ArrayList<>(); for (int j=0; j < elements; j++) al.add(new Long(j)); LinkedList ll = new LinkedList<>(); for (int j=0; j < elements; j++) ll.add(new Long(j)); int indices[] = new int[elements / 100]; Random r = new Random(19700101); for (int i=0; i < indices.length; i++) { indices[i] = r.nextInt(indices.length); } t0 = System.currentTimeMillis(); BigDecimal sum = new BigDecimal(0); for (int i=0; i < indices.length; i++) { sum.add( new BigDecimal(al.get(indices[i])) ); } t1 = System.currentTimeMillis(); sum = new BigDecimal(0); for (int i=0; i < indices.length; i++) { sum.add( new BigDecimal(ll.get(indices[i])) ); } t2 = System.currentTimeMillis(); System.out.println("Access ArrayList: "+(t1-t0)+" ms, cnt="+elements+", tries="+indices.length); System.out.println("Access LinkedList: "+(t2-t1)+" ms, cnt="+elements+", tries="+indices.length); -- Access ArrayList: 12 ms, cnt=2000000, tries=20000 Access LinkedList: 371 ms, cnt=2000000, tries=20000
Czy ArrayList jest szybsze od LinkedList?
int elements = 1000000;
int tries = 100;
String values[] = new String[elements];
for (int k=0; k < elements; k++) {
values[k] = String.valueOf(k).intern();
}
long t0 = System.currentTimeMillis();
for (int i=0; i < tries; i++) {
ArrayList al = new ArrayList();
for (int j=0; j < elements; j++)
al.add(values[j]);
}
long t1= System.currentTimeMillis();
for (int i=0; i < tries; i++) {
LinkedList ll = new LinkedList();
for (int j=0; j < elements; j++)
ll.add(values[j]);
}
long t2 = System.currentTimeMillis();
System.out.println("Add to ArrayList: "+(t1-t0)/100+" ms avg, cnt="+elements+", tries="+tries);
System.out.println("Add to LinkedList: "+(t2-t1)/100+" ms avg, cnt="+elements+", tries="+tries);
-- Add to ArrayList: 33 ms avg, cnt=2000000, tries=100 Add to LinkedList: 51 ms avg, cnt=2000000, tries=100 Add to ArrayList: 18 ms avg, cnt=1000000, tries=100 Add to LinkedList: 12 ms avg, cnt=1000000, tries=100
poniedziałek, stycznia 30, 2017
czwartek, stycznia 26, 2017
piątek, stycznia 20, 2017
poniedziałek, stycznia 16, 2017
Odkurzanie całego mieszkania na jednym gniazdku
Odkurzacz Zelmer Protecto ma zasięg 11m. Podłączając się do jednego gniazdka można odkurzyć całe mieszkanie. W rękojeści jest pilot sterujący ciągiem i włącznik. Urządzenie jest relatywnie ciche, dobrze zbiera brud z podłogi, dywanu czy dziecięcej maty. Najmniejszy wymiar ma poniżej 27,5 cm i zmieści się w małej szafie. Zelmer produkowany jest w Chinach, ma 4 lata gwarancji.
-- UPDATE --
Urządzenie jest prawdopodobnie robione przez dzieci w chińskiej fabryce, bo rura odkurzacza odkleja się z dwóch stron. Rura ma oplot z drutu stalowego, należy ją nakręcić na gwintowane złączki. Wymaga to siły dorosłej osoby. Klejenie nie działa, bo przy wielokrotnym ciągnięciu rury spoina puszcza. Problem można naprawić samodzielnie.
środa, stycznia 11, 2017
Tibco BW cannot receive big JMS messages
If you have JMS message exceeding 10MB it is likely that with default receiver's timeout 10s you won't get it fast. For SOAP over JMS and Service component default value is just 1s, but can be overriden with bw.plugin.jms.receiverTimeout property.
piątek, stycznia 06, 2017
Kody błędów płyty indukcyjnej Bosch
F8 - zabezpieczenie przed spaleniem garnka
F0-F9 - błąd wewnętrzny
F2, F4 - ochrona przed spaleniem elektroniki płyty
F5 - zbyt gorący garnek, należy go zdjąć
U2, U3 - przegrzanie strefy grzejnej
U1 - nieprawidłowe napięcie zasilające
F0-F9 - błąd wewnętrzny
F2, F4 - ochrona przed spaleniem elektroniki płyty
F5 - zbyt gorący garnek, należy go zdjąć
U2, U3 - przegrzanie strefy grzejnej
U1 - nieprawidłowe napięcie zasilające
środa, stycznia 04, 2017
wtorek, stycznia 03, 2017
wtorek, grudnia 27, 2016
piątek, grudnia 02, 2016
poniedziałek, października 31, 2016
czwartek, października 27, 2016
Fix slow and unresponsive LibreOffice in Ubuntu 16.10
echo "export SAL_USE_VCLPLUGIN=gtk" >> /etc/profile
czwartek, października 20, 2016
Johny Mnemonic - Memory Doubler
cat /etc/default/grub | grep zswap
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet zswap.enabled=1 zswap.max_pool_percent=50"
https://www.ibm.com/developerworks/community/blogs/fe313521-2e95-46f2-817d-44a4f27eba32/entry/new_linux_zswap_compression_functionality7?lang=en
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet zswap.enabled=1 zswap.max_pool_percent=50"
https://www.ibm.com/developerworks/community/blogs/fe313521-2e95-46f2-817d-44a4f27eba32/entry/new_linux_zswap_compression_functionality7?lang=en
niedziela, października 16, 2016
środa, września 14, 2016
How to extract text from MS HTML
public static String extractTextFromHtml(String html, boolean isForJson) {
StringBuilder sb = new StringBuilder();
boolean ignore = false;
boolean isXmlData = false;
boolean closing = false;
for (int i=0; i < html.length(); i++) {
char c = html.charAt(i);
if (c=='<' & !ignore) {
ignore = true;
closing = false;
}
else if (c=='&' && !ignore) {
int end = html.indexOf(";", i+1);
if (end!=-1) {
Boolean isNumber = null;
Boolean isEntity = null;
for (int x=i+1; x < end; x++) {
char ch = html.charAt(x);
if ((ch >='0' && ch <= '9') || (ch=='#' && x==c+1)) {
if (isNumber == null)
isNumber = true;
else
isNumber &= true;
}
else if (ch==' ') {
if (isEntity==null)
isEntity = false;
else
isEntity = isNumber = false;
}
else
isEntity = true;
}
if (Boolean.TRUE.equals(isNumber) || Boolean.TRUE.equals(isEntity)) {
if (Boolean.TRUE.equals(isNumber)) {
String num = html.substring(i+2, end);
sb.append(Character.toString((char)Integer.valueOf(num).intValue()));
}
int add = (end - i);
i += add;
}
else if (ignore && c=='/') {
closing = true;
}
else if (ignore && c=='>') {
ignore = false;
if (closing && isXmlData)
closing = isXmlData = false;
}
else if (ignore && c==':') {
isXmlData = true;
}
else if (!ignore && !isXmlData) {
if (c=='„' || c=='”' && isForJson)
c = '"';
if (c=='"' && i>1 && html.charAt(i-1)!='\\' && isForJson)
sb.append('\\');
sb.append(c);
}
}
String s = sb.toString().trim();
if (s.startsWith("ĘĄ"))
return s.substring(2, s.length());
return s;
}
Subskrybuj:
Posty (Atom)




















