zoukankan      html  css  js  c++  java
  • 性能速度

    <!DOCTYPE html>
    <html>
    <body>

    <script>
    document.write(multSilgarth3(99999999));
    function multSilgarth1(n) {
      var array = [];
      var result = 0;
      for (var i = 1; i < n; i ++) {
        if (i % 3 == 0 || i % 5 == 0) {
          array.push(i);
        }
      }
      for (var num of array) {
        result += num;
      }
      return result;
    }
    function multSilgarth2(n) {
      var array = [];
      for (var i = 1; i < n; i ++) {
        if (i % 3 == 0 || i % 5 == 0) {
          array.push(i);
        }
      }
      return array.reduce(function(prev, current) {
        return prev + current;
      });
    }
    function multSilgarth3(n) {
      var array = [];
      while (n >= 1) {
        n--;
        if (n%3==0||n%5==0) {
          array.push(n);
        }
      }
      return array.reduce(function(prev, current) {
        return prev + current;
      });
    }
    function multSilgarth4(n) {
      var sum = 0;
      while (n >= 1) {
        n--;
        if (n%3==0||n%5==0) {
          sum += n;
        }
      }
      return sum;
    }
    function multSilgarth5(n) {
      n = n-1;
      var sum = 0;
      for (n; n >= 1 ;n--) {
        (n%3==0||n%5==0) ? sum += n : null;
      }
      return sum;
    }
    function multSilgarth(N) {
      var threes = Math.floor(--N / 3);
    document.write(threes+ "<br>");
      var fives = Math.floor(N / 5);
    document.write(fives+ "<br>");
      var fifteen = Math.floor(N / 15);
    document.write(fifteen + "<br>");
      return (3 * threes * (threes + 1) + 5 * fives * (fives + 1) - 15 * fifteen * (fifteen + 1)) / 2;
    }
    </script>

    </body>
    </html>
    https://github.com/xitu/gold-miner/blob/master/TODO/what-i-learned-from-writing-six-functions-that-all-did-the-same-thing.md

  • 相关阅读:
    全面了解HTTP和HTTPS(开发人员必备)
    这几款前端必备构建工具合辑,我们帮你整理好了!
    扎心!程序员泪奔的8个瞬间
    Centos7 自定义systemctl服务脚本
    nginx配置优化+负载均衡+动静分离详解
    nginx负载均衡配置
    keepalived高可用反向代理的nginx
    Tomcat相关目录及配置文件
    tomcat快速入门
    基于keepalived双主模型的高可用LVS
  • 原文地址:https://www.cnblogs.com/RadyGo/p/6074751.html
Copyright © 2011-2022 走看看