Thursday, November 5, 2015

Java: Poor performance of Files.newDirectoryStream() with wildcards

Here are results of comparison of getting single result of Files.newDirectoryStream() and File.exists().

Wildcards pattern I used is "prefix_prefix_prefix____?.tmp". Results are almost the same when calling Files.newDirectoryStream() with string argument with no wildcard (direct match).

Test results 1:

measure exists speed in loop 1000 times - BEGIN
measure exists speed in loop 1000 times - END
Elapsed: 5 ms

Test results 2:

measure wildcards match speed in loop 1000 times - BEGIN
measure wildcards match speed in loop 1000 times - END
Elapsed: 80590 ms

Test environment:

Windows 7 system
NTFS system
Folder with 90 000 files (zero length)
Java 8

dir approach

I looped this MSDOS command for 1000 times to check performance of dir with wildcards:

dir prefix_prefix_prefix____*.tmp

I tested it in loop with:
FOR /L %i IN (1,1,1000) DO @dir prefix_prefix_prefix____*.tmp > nul

It finished in about 1000ms. I suppose this time is spend mainly in calling DIR command by command interpreter.

Conclusion

Files.newDirectoryStream() has absolutely no performance optimizations when working with wildcards.

Relative information

File.list also has poor performance

Source code of newDirectoryStream

    public static DirectoryStream<Path> newDirectoryStream(Path dir, String glob)
        throws IOException
    {
        // avoid creating a matcher if all entries are required.
        if (glob.equals("*"))
            return newDirectoryStream(dir);

        // create a matcher and return a filter that uses it.
        FileSystem fs = dir.getFileSystem();
        final PathMatcher matcher = fs.getPathMatcher("glob:" + glob);
        DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
            @Override
            public boolean accept(Path entry)  {
                return matcher.matches(entry.getFileName());
            }
        };
        return fs.provider().newDirectoryStream(dir, filter);
    }

Wednesday, September 9, 2015

Hidden AVG buttons - How to stay on AVG Free edition

AVG is great antivirus software. It has free and paid editions. But Free version often offers you an update to the paid one. You have to read notifications of the program, but look for the "hidden" Decline button.

Here are some example of this hidden buttons of AVG:



Good luck.

And the free version is good enough for most users.

Sunday, August 16, 2015

Redirect http page to https in .htaccess file

You could use this code to redirect a request to HTTPS in apache:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Tuesday, March 10, 2015

Програмистки поговорки

Програмистки хумор:
- Бърза програма - срам за програмиста.
- Трай, потребителю, за работещо приложение.
- Да би мирно седяло, не би exception видяло!
- Бъг година храни.
- Програмистът работата си мени, но хигиената - никога!
- Когато клиентът не отива при програмиста, програмистът му пуска вирус.
- Дваж copy-рай, веднъж paste-вай.
- Бъг бъг избива.
- Програмистът не пада по-далеч от кръчмата.
- Който прави бъг другиму, сам влиза в безкраен цикъл.
- На сисадмин вируси ще продава!
- На програмата паметта все й е малко.
- Бъг по бъг - програма прави.
- Не търси в кода смисъл!
- За тийм лидера приказват, а пък той под масата.
- Барабар junior със senior-ите.
- Признат бъг - половин бъг.
- Не дърпай сисадмина за опашката!
- Ако е тийм лидер, да е рошав!
- Шеф високо, клиент далеко.

- На чужд код и 100 рефакторинга са малко.

Други забавни смешки може да намерите тук.

Wednesday, January 28, 2015

Artisteer cannot create localized sites - no localized headline nor slogan

Artisteer, a template generator for joomla cannot create localized headlines and slogans. This was a comment from official forum.

What a joke!!! What a limitation!!! By now, 12 days passed and I have not answer on question about how could I localize them. What if this was my blocker for me? I cannot realize that noone could answer this SIMPLE question.

Artiseer - what a joke! I will have a look in its alternative - Template Toaster. It seems that such a promoted software (Artisteer) has so much limitations at first sight...

Monday, December 8, 2014

Strings in switch Statements - available from Java 7 on

Good to know - Java 7 supports String type in switch statement.

Note 1: String are compared via equals() method - note, not via equalsIgnoreCase! and not via  ==.
Note 2: switch argument must not be null - else  NullPointerException is thrown.

Example code:
        String color = "#0000FF";
        color = color.toLowerCase();
        switch (color) {
          case "#0000ff":
              System.out.println("BLUE");
          break;
          case "#ff0000":
              System.out.println("RED");
          break;
          default:
              System.out.println("INVALID COLOR CODE");
        }

More: Oracle info on the topic.