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 容器并创建和保存它
       */
      createIoc(config, mainModule);

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

      /*
       * 分析本地化字符串
       */
      evalLocalization(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);
    }
    // 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

        UrlMapping mapping;

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

        try {

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

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

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

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

            /*
             * 分析本地化字符串
             */
            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

  public void filter(InterceptorChain chain) throws Throwable {
    if (!LOG.isDebugEnabled()) {
      chain.doChain();
      return;
    }
    Stopwatch stopwatch = Stopwatch.begin();
    chain.doChain();
    stopwatch.stop();
    LOG.debugf("ExecutionTime %dms in %s",stopwatch.getDuration(),chain.getCallingMethod());
  }
View Full Code Here

    dao.create(Pojo.class, true);
    dao(dao,list);
  }

  public static void dao(Dao dao, List<Pojo> list){
    Stopwatch sw = Stopwatch.begin();
    dao.fastInsert(list);
    sw.stop();
    System.out.printf("Dao 批量插入%d条,耗时%dms\n",num,sw.getDuration());
  }
View Full Code Here

    System.out.printf("Dao 批量插入%d条,耗时%dms\n",num,sw.getDuration());
  }
 
  public static void jdbc(DataSource ds, List<Pojo> list) throws Throwable{
   
    Stopwatch sw = Stopwatch.begin();
    Connection conn = ds.getConnection();
    PreparedStatement ps = conn.prepareStatement("insert into tb_pojo(name) values(?)");
    for (Pojo pojo : list) {
      ps.setString(1, pojo.getName());
      ps.addBatch();
    }
    ps.executeBatch();
    conn.commit();
    conn.close();
   
    sw.stop();
    System.out.printf("JDBC 批量插入%d条,耗时%dms\n",num,sw.getDuration());
  }
View Full Code Here

    @Test
    public void json() {
        nutzJson(10000);
        fastJson(10000);
       
        Stopwatch sw = Stopwatch.begin();
        nutzJson(50*10000);
        sw.stop();
        System.out.println("Nutz-Json 50w次耗时: " + sw.getDuration());
       
        sw.start();
        fastJson(50*10000);
        System.out.println("Fast-Json 50w次耗时: " + sw.getDuration());
       
        //-------------------------------------------------------------------
        sw.start();
        nutzJson(50*10000);
        sw.stop();
        System.out.println("Nutz-Json 50w次耗时: " + sw.getDuration());
       
        sw.start();
        fastJson(50*10000);
        sw.stop();
        System.out.println("Fast-Json 50w次耗时: " + sw.getDuration());
    }
View Full Code Here

        UploadMonitor mon = new UploadMonitor(monLock, req.getSession(), out, monInterval);
        Thread monThread = new Thread(mon, "UploadingMonitor");
        monThread.start();

        out.println("Begin...");
        Stopwatch sw = null;
        try {
            sw = Stopwatch.run(new Atom() {
                public void run() {
                    try {
                        up.parse(req, uc);
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.