<commit_before>/*
 * Copyright 2014 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.vaadin.maddon;

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItemContainer;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.Test;

/**
 *
 */
public class DynaBeanBasedContainer {

    Random r = new Random(0);

    private List<Person> getListOfPersons(int total) {
        List<Person> l = new ArrayList<Person>(total);
        for (int i = 0; i < total; i++) {
            Person p = new Person();
            p.setFirstName("Fist" + i);
            p.setLastName("Lastname" + i);
            p.setAge(r.nextInt(100));
            l.add(p);
        }
        return l;
    }

    final static int amount = 1000000;

    private List<Person> persons = getListOfPersons(amount);

    @Test
    public void testMemoryUsage() {
        System.out.println("\n Testing List container from Maddon");

        long initial = reportMemoryUsage();

        Container lc = new ListContainer<Person>(persons);
        System.out.println("After creation");
        long after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        for (int i = 0; i < amount; i++) {
            Item item = lc.getItem(persons.get(i));
            String str;
            str = item.getItemProperty("firstName").toString();
        }

        System.out.println("After loop");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        // call to avoid GC:n the whole container
        lc.getItemIds();

        System.out.println("After GC");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

    }

    @Test
    public void testMemoryUsageStd() {
        System.out.println("\n Testing BeanItemContainer from core Vaadin");

        long initial = reportMemoryUsage();

        Container lc = new BeanItemContainer<Person>(persons);
        System.out.println("After creation");
        long after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        for (int i = 0; i < amount; i++) {
            Item item = lc.getItem(persons.get(i));
            String str;
            str = item.getItemProperty("firstName").toString();
        }

        System.out.println("After loop");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        // call to avoid GC:n the whole container
        lc.getItemIds();

        System.out.println("After GC");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

    }

    private long reportMemoryUsage() {
        try {
            System.gc();
            Thread.sleep(1000);
            System.gc();
            Thread.sleep(1000);
            System.gc();
            Thread.sleep(1000);
            System.gc();
        } catch (InterruptedException ex) {
        }
        MemoryUsage mu = ManagementFactory.getMemoryMXBean().
                getHeapMemoryUsage();
        System.out.println("Memory used (M):" + mu.getUsed() / 1000000);
        return ManagementFactory.getMemoryMXBean().
                getHeapMemoryUsage().getUsed();
    }

}<commit_msg>improved dyna table test, added execution time reporting<commit_after>/*
 * Copyright 2014 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.vaadin.maddon;

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItemContainer;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Logger;
import org.junit.Test;

/**
 *
 */
public class DynaBeanBasedContainer {

    Random r = new Random(0);

    private List<Person> getListOfPersons(int total) {
        List<Person> l = new ArrayList<Person>(total);
        for (int i = 0; i < total; i++) {
            Person p = new Person();
            p.setFirstName("Fist" + i);
            p.setLastName("Lastname" + i);
            p.setAge(r.nextInt(100));
            l.add(p);
        }
        return l;
    }

    final static int amount = 1000000;

    private List<Person> persons = getListOfPersons(amount);

    @Test
    public void testMemoryUsage() {
        System.out.println("\n Testing List container from Maddon");

        long initial = reportMemoryUsage();

        long ms = System.currentTimeMillis();
        ListContainer lc = new ListContainer<Person>(persons);
        System.out.println(
                "After creation (took " + (System.currentTimeMillis() - ms) + ")");
        long after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        ms = System.currentTimeMillis();
        for (int i = 0; i < amount; i++) {
            Item item = lc.getItem(persons.get(i));
            String str;
            str = item.getItemProperty("firstName").toString();
        }

        System.out.println(
                "After loop (took " + (System.currentTimeMillis() - ms) + ")");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        // call to avoid GC:n the whole container
        lc.getItemIds();
        System.out.println("After GC");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

    }

    @Test
    public void testMemoryUsageStd() {
        System.out.println("\n Testing BeanItemContainer from core Vaadin");

        long initial = reportMemoryUsage();

        long ms = System.currentTimeMillis();
        BeanItemContainer lc = new BeanItemContainer<Person>(persons);
        System.out.println(
                "After creation (took " + (System.currentTimeMillis() - ms) + ")");
        long after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        ms = System.currentTimeMillis();
        for (int i = 0; i < amount; i++) {
            Item item = lc.getItem(persons.get(i));
            String str;
            str = item.getItemProperty("firstName").toString();
        }

        System.out.println(
                "After loop (took " + (System.currentTimeMillis() - ms) + ")");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

        // call to avoid GC:n the whole container
        lc.getItemIds();

        System.out.println("After GC");
        after = reportMemoryUsage();
        System.err.println("Delta (bytes)" + (after - initial));

    }

    private long reportMemoryUsage() {
        try {
            System.gc();
            Thread.sleep(100);
            System.gc();
            Thread.sleep(100);
            System.gc();
            Thread.sleep(100);
            System.gc();
        } catch (InterruptedException ex) {
        }
        MemoryUsage mu = ManagementFactory.getMemoryMXBean().
                getHeapMemoryUsage();
        System.out.println("Memory used (M):" + mu.getUsed() / 1000000);
        return ManagementFactory.getMemoryMXBean().
                getHeapMemoryUsage().getUsed();
    }

}
{'fraction_non_alphanumeric': 0.12437987243090007, 'fraction_numerical': 0.00933144342074179, 'mean_word_length': 2.362589356632248, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6270108', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2276, 'n_words': 633}