惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
H
Hacker News: Front Page
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Google Online Security Blog
Google Online Security Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
T
Tenable Blog
博客园 - 叶小钗
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
量子位
P
Proofpoint News Feed
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
宝玉的分享
宝玉的分享
Recorded Future
Recorded Future
The Register - Security
The Register - Security
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
S
Schneier on Security
V
Vulnerabilities – Threatpost
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
G
GRAHAM CLULEY
G
Google Developers Blog
月光博客
月光博客
V
V2EX
T
Troy Hunt's Blog
A
Arctic Wolf

Scala

这个分类好久没新帖子了,记录下最新用 scala 3 写的项目 - V2EX sbt run 的时候,能不能跳过 compile 直接 run? - V2EX 还有必要用 scala 吗 - V2EX 有 scala 兄弟吗?有招 scala 的公司吗? - V2EX Scala 单元测试 - V2EX scala 模型导出问题 - V2EX 想用 Springboot 做后端接口,但组里 scala 大佬希望我用 Akka Http 怎么办 - V2EX 可能是家庭背景最深厚的程序员写的书... - V2EX sbt 为什么能这么垃圾? - V2EX sbt 1.3.0 released, 依赖管理从 ivy 变为 Coursier - V2EX 如何停止已经提交到 Spark 集群上的任务? - V2EX Scala 元编程:在日志库中的应用 - V2EX 关于《Scala 编程(3rd)》中, 20.6 抽象类型 P424 的疑问 - V2EX 请教下关于用 Flume+kafka+Spark 实现实时监控错误日志报警的功能 - V2EX 闲话 Scala Native: 初次见面,请多多关照 - V2EX Scala 中不带具体实现的 object 是什么用法 - V2EX scala 命令行删除字符不能正常显示 spark 技术面试被问到个问题,有点问懵逼了,求指点 - V2EX scala 中 _ 的语法问题 - V2EX [小广告] scala 中文 telegram 群组: t.me/scala_zh Scala 中国社区、微信群? - V2EX Scala's types of types 译文 - V2EX Scala 自学笔记-参考书籍 Programming in Scala 第三版 - V2EX scala 如何实现某个代码段同一时刻只能有一个进程在读,其他进程只能等待。 请问该怎样结合实践去学习 Scala,谢谢! - V2EX 欢迎来访开放源码的 PlayScala 社区(http://www.playscala.cn) - V2EX 请问我下载了乌云的 digatalAllData,说明上写着用 case class 解析出数据,那有没有详细的方法? - V2EX 嘿,Scala 这货你们都应用在什么项目上了,打算接触试试呢~ - V2EX sbt package 将 scala 源代码一并打包进去? - V2EX 大家都用什么 orm 或 mysql db library - V2EX 询问有关 Scala 的实习, 工业应用等 - V2EX sbt 的自定义 resolvers 被-Dsbt.override.build.repos=true 覆盖掉了 - V2EX 谁能说说 scala 和 python 的区别,有木有必要学习 scala? - V2EX IDEA 的 sbt 依赖解决问题 - V2EX 话说 V2 里有搞 Scala 的同学吗? - V2EX 还有必要学 scala 吗? - V2EX Scala China 的 Telegram 群 - V2EX Scala 2.12 will require Java 8. - V2EX 仿照 scrapy 的设计用 scala 写了一个爬虫框架 - V2EX V2EX 里有 scala 爱好者吗? - V2EX 此处有 Scala 爱好者吗? - V2EX 10 Scala One Liners to Impress Your Friends - V2EX 有什么方法,能够使得主程序在 Actor 执行了 exit 后才继续执行么~? - V2EX 李光耀似乎有个能称为 Scala 大神的孙子! - V2EX Scala on Android - V2EX scala 值得学习么?被逼着学习这货了:( - V2EX Scala 怎么做如下变换:(A,B,C) => (A,(B,C)) (B,(A,C)) (C,(A,B)) - V2EX Scala By Example,Scala 之父 Martin 今天刚更新/发布的教程 - V2EX
集合类型 filter 后执行 foreach 的效率 比 foreach 里写 if 来的慢 - V2EX
muziling · 2020-05-21 · via Scala
object test {
  def main(args: Array[String]): Unit = {
    def listTestD = (0 to 20000000).toList
    var l1 = System.currentTimeMillis()
    var sum = 0
    listTestD.foreach{x=> if (x%2==0) sum = x}
    println(System.currentTimeMillis()-l1)
    sum = 0
    l1 = System.currentTimeMillis()
    listTestD.filter(_%2==0).foreach(sum = _)
    println(System.currentTimeMillis()-l1)
  }
}

执行结果是: 17585, 21059 效率差 20%左右

避免缓存,对掉两个 foreach

object test {
  def main(args: Array[String]): Unit = {
    def listTestD = (0 to 20000000).toList
    var l1 = System.currentTimeMillis()
    var sum = 0
    listTestD.filter(_%2==0).foreach(sum = _)
    println(System.currentTimeMillis()-l1)
    sum = 0
    l1 = System.currentTimeMillis()
    listTestD.foreach{x=> if (x%2==0) sum = x}
    println(System.currentTimeMillis()-l1)
  }
}

执行结果是: 35082, 16201 效率差近 50%。

如果 listTestD 存储一个对象的内容,效率是不是会差更大?