Package org.nutz.lang

Examples of org.nutz.lang.Stopwatch


        final Context context = Lang.context("{num:0}");
        context.set("z", z);

        System.out.println("\n" + Strings.dup('=', 100));

        Stopwatch sw = Stopwatch.run(new Atom() {
            public void run() {
                int num = 0;
                for (int i = 0; i < max; i++)
                    num = num + (i - 1 + 2 - 3 + 4 - 5 + 6 - 7) - z.abc(i);
                System.out.println("Num: " + num);
            }
        });

        System.out.println("\n" + Strings.dup('=', 100));
       
        Stopwatch sw3 = Stopwatch.run(new Atom() {
            public void run() {
                try {
                    context.set("num", 0);
                    for (int i = 0; i < max; i++)
                        context.set("num", El.eval(context.set("i", i), elstr));
                    System.out.println("Num: " + context.getInt("num"));
                }
                catch (Exception e) {
                    throw Lang.wrapThrow(e);
                }
            }
        });
        System.out.println("\n" + Strings.dup('=', 100));
       
        Stopwatch sw4 = Stopwatch.run(new Atom() {
            public void run() {
                try {
                    El el2pre = new El(elstr);
                    context.set("num", 0);
                    context.set("z", z);
                    for (int i = 0; i < max; i++)
                        context.set("num", el2pre.eval(context.set("i", i)));
                    System.out.println("Num: " + context.getInt("num"));
                }
                catch (Exception e) {
                    throw Lang.wrapThrow(e);
                }
            }
        });
        System.out.println("\n" + Strings.dup('=', 100));
       
        Stopwatch sw5 = Stopwatch.run(new Atom() {
            public void run() {
                try {
                    El el2pre = new El(elstr);
                    context.set("num", 0);
                    context.set("z", z);
                    for (int i = 0; i < max; i++)
                        context.set("num", el2pre.eval(context.set("i", i)));
                    System.out.println("Num: " + context.getInt("num"));
                }
                catch (Exception e) {
                    throw Lang.wrapThrow(e);
                }
            }
        });
        System.out.println("\n" + Strings.dup('=', 100));

        System.out.printf("\n%20s : %s", "Invoke", sw.toString());
        System.out.printf("\n%20s : %s", "Reflect", sw3.toString());
        System.out.printf("\n%20s : %s", "Reflect", sw4.toString());
        System.out.printf("\n%20s : %s", "Reflect", sw5.toString());
        System.out.println();

    }
View Full Code Here


        UrlMapping mapping;

        /*
         * 准备计时
         */
        Stopwatch sw = Stopwatch.begin();

        try {

            /*
             * 检查主模块,调用本函数前,已经确保过有声明 MainModule 了
             */
            Class<?> mainModule = config.getMainModule();

            /*
             * 创建上下文
             */
            createContext(config);

            /*
             * 检查 Ioc 容器并创建和保存它
             */
            Ioc ioc = createIoc(config, mainModule);

            /*
             * 组装UrlMapping
             */
            mapping = evalUrlMapping(config, mainModule, ioc);

            /*
             * 分析本地化字符串
             */
            evalLocalization(config, mainModule);

            // 初始化SessionProvider
            createSessionProvider(config, mainModule);

            /*
             * 执行用户自定义 Setup
             */
            evalSetup(config, mainModule);
        }
        catch (Exception e) {
            if (log.isErrorEnabled())
                log.error("Error happend during start serivce!", e);
            throw Lang.wrapThrow(e, LoadingException.class);
        }

        // ~ Done ^_^
        sw.stop();
        if (log.isInfoEnabled())
            log.infof("Nutz.Mvc[%s] is up in %sms", config.getAppName(), sw.getDuration());

        return mapping;

    }
View Full Code Here

    }

    public void depose(NutConfig config) {
        if (log.isInfoEnabled())
            log.infof("Nutz.Mvc[%s] is deposing ...", config.getAppName());
        Stopwatch sw = Stopwatch.begin();

        // Firstly, upload the user customized desctroy
        try {
            Setup setup = config.getAttributeAs(Setup.class, Setup.class.getName());
            if (null != setup)
                setup.destroy(config);
        }
        catch (Exception e) {
            throw new LoadingException(e);
        }
        finally {
            SessionProvider sp = config.getSessionProvider();
            if (sp != null)
                sp.notifyStop();
            // If the application has Ioc, depose it
            Ioc ioc = config.getIoc();
            if (null != ioc)
                ioc.depose();
        }

        // Done, print info
        sw.stop();
        if (log.isInfoEnabled())
            log.infof("Nutz.Mvc[%s] is down in %sms", config.getAppName(), sw.getDuration());
    }
View Full Code Here

TOP

Related Classes of org.nutz.lang.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.